Skip to content

Commit

Permalink
Add resize observer for block
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Aug 19, 2022
1 parent 5a8c121 commit cbb5ee1
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit cbb5ee1

Please sign in to comment.