Skip to content

Commit

Permalink
Remove event listener on resize stop.
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed May 10, 2024
1 parent 795d661 commit 20315d6
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ function GridItemResizerInner( {
},
};

// Controller to remove event listener on resize stop.
const controller = new AbortController();

return (
<BlockPopoverCover
className="block-editor-grid-item-resizer"
Expand Down Expand Up @@ -161,15 +164,16 @@ function GridItemResizerInner( {
* isn't directly above the handle, so we try to detect if it happens
* outside the grid and dispatch a mouseup event on the handle.
*/
const rootElementParent = rootBlockElement.parentElement;
const rootElementParent =
rootBlockElement.closest( 'body' );
rootElementParent.addEventListener(
'mouseup',
() => {
event.target.dispatchEvent(
new Event( 'mouseup', { bubbles: true } )
);
},
true
{ signal: controller.signal, capture: true }
);
} }
onResizeStop={ ( event, direction, boxElement ) => {
Expand Down Expand Up @@ -213,6 +217,8 @@ function GridItemResizerInner( {
columnSpan: columnEnd - columnStart + 1,
rowSpan: rowEnd - rowStart + 1,
} );
// Removes event listener added in onResizeStart.
controller.abort();
} }
/>
</BlockPopoverCover>
Expand Down

0 comments on commit 20315d6

Please sign in to comment.