Skip to content

Commit

Permalink
Ensure resizing the block editor will update the block popover dimens…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
andrewserong committed Apr 26, 2023
1 parent b9138d7 commit 9e42a8b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/block-editor/src/components/block-popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ function BlockPopover(
};
}, [ selectedElement ] );

// When cover target is enabled, the popover dimensions need to be recomputed
// when the window is resized. This is to ensure that the calculated dimensions
// of the popover are correct when the block editor is resized.
useLayoutEffect( () => {
if ( ! __unstableCoverTarget || ! selectedElement ) {
return;
}

const defaultView = selectedElement?.ownerDocument.defaultView;
defaultView.addEventListener(
'resize',
forceRecomputePopoverDimensions
);

return () => {
defaultView.removeEventListener(
'resize',
forceRecomputePopoverDimensions
);
};
}, [ __unstableCoverTarget, selectedElement ] );

const style = useMemo( () => {
if (
// popoverDimensionsRecomputeCounter is by definition always equal or greater
Expand Down

0 comments on commit 9e42a8b

Please sign in to comment.