From cbb5ee1c95d2a2f3c212378939471d4228c296ff Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Fri, 19 Aug 2022 12:26:41 +0800 Subject: [PATCH] Add resize observer for block --- .../block-tools/use-block-toolbar-popover-props.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js b/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js index c059ff5bc7f2d..2c1c5e768953b 100644 --- a/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js +++ b/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js @@ -92,8 +92,19 @@ export default function useBlockToolbarPopoverProps( { const view = contentElement?.ownerDocument?.defaultView; view?.addEventHandler?.( 'resize', updateProps ); + // Update the toolbar props on block resize. + let resizeObserver; + if ( view.ResizeObserver ) { + resizeObserver = new view.ResizeObserver( updateProps ); + resizeObserver.observe( selectedBlockElement ); + } + return () => { view?.removeEventHandler?.( 'resize', updateProps ); + + if ( resizeObserver ) { + resizeObserver.disconnect(); + } }; // The deps will update the toolbar props if: