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 authored and ockham committed Dec 3, 2021
1 parent fe06647 commit 5be0ffd
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
Original file line number Diff line number Diff line change
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 5be0ffd

Please sign in to comment.