Skip to content

Commit b941a1e

Browse files
tellthemachinesandrewserongnoisysocks
authored
Fix grid item resizing in non-iframed editor. (#61636)
Co-authored-by: tellthemachines <[email protected]> Co-authored-by: andrewserong <[email protected]> Co-authored-by: noisysocks <[email protected]>
1 parent 32bcc86 commit b941a1e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/block-editor/src/components/grid-visualizer/grid-item-resizer.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ function GridItemResizerInner( {
6363
* This ref is necessary get the bounding client rect of the resizer,
6464
* because it exists outside of the iframe, so its bounding client
6565
* rect isn't the same as the block element's.
66+
* It needs to be added to a dummy element because we can't be sure if
67+
* the popover or the resizer are on the page when we need them.
6668
*/
6769
const resizerRef = useRef( null );
6870

@@ -131,7 +133,6 @@ function GridItemResizerInner( {
131133
clientId={ clientId }
132134
__unstablePopoverSlot="block-toolbar"
133135
additionalStyles={ styles }
134-
__unstableContentRef={ resizerRef }
135136
>
136137
<ResizableBox
137138
className="block-editor-grid-item-resizer__box"
@@ -164,9 +165,8 @@ function GridItemResizerInner( {
164165
* isn't directly above the handle, so we try to detect if it happens
165166
* outside the grid and dispatch a mouseup event on the handle.
166167
*/
167-
const rootElementParent =
168-
rootBlockElement.closest( 'body' );
169-
rootElementParent.addEventListener(
168+
controller.abort();
169+
event.target.ownerDocument.addEventListener(
170170
'mouseup',
171171
() => {
172172
event.target.dispatchEvent(
@@ -221,6 +221,10 @@ function GridItemResizerInner( {
221221
controller.abort();
222222
} }
223223
/>
224+
<div
225+
className="block-editor-grid-item-resizer__dummy"
226+
ref={ resizerRef }
227+
></div>
224228
</BlockPopoverCover>
225229
);
226230
}

packages/block-editor/src/components/grid-visualizer/style.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@
3232
}
3333
}
3434

35+
.block-editor-grid-item-resizer__dummy {
36+
position: absolute;
37+
width: 100%;
38+
height: 100%;
39+
z-index: -1;
40+
}
41+

0 commit comments

Comments
 (0)