Skip to content

Commit

Permalink
Block Styles: check for existence of scroll container (#37010)
Browse files Browse the repository at this point in the history
* Let's check if the scrollContainer can be found before trying to use its property `scrollTop`.

* Moving default top position to a const and moving the comment.
  • Loading branch information
ramonjd committed Nov 30, 2021
1 parent 201ee37 commit 33231a1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/block-editor/src/components/block-styles/index.js
Expand Up @@ -35,6 +35,11 @@ function BlockStylesPreviewPanelFill( { children, scope, ...props } ) {
);
}

// Top position (in px) of the Block Styles container
// relative to the editor pane.
// The value is the equivalent of the container's right position.
const DEFAULT_POSITION_TOP = 16;

// Block Styles component for the Settings Sidebar.
function BlockStyles( {
clientId,
Expand All @@ -60,7 +65,8 @@ function BlockStyles( {
const scrollContainer = document.querySelector(
'.interface-interface-skeleton__content'
);
setContainerScrollTop( scrollContainer.scrollTop + 16 );
const scrollTop = scrollContainer?.scrollTop || 0;
setContainerScrollTop( scrollTop + DEFAULT_POSITION_TOP );
}, [ hoveredStyle ] );

if ( ! stylesToRender || stylesToRender.length === 0 ) {
Expand Down

0 comments on commit 33231a1

Please sign in to comment.