Skip to content

Commit aa17cbd

Browse files
jeryjscruffian
andauthored
Allow submenu flyout menus to be visible outside of template part canvas (WordPress#72013)
When editing a navigation template part or thin template part with a navigation (like a header), the submenus dropdown menus are contained within the small area of the iframe and blocked from overflowing. This makes the submenus unusable as they are cut off. This commit expands the iframe to be the full size of the canvas, and fakes a background on the iframe HTML element by hardcoding the #ddd color as a background. Then, the body has the color of the user's chosen background and is centered using inlined CSS. --------- Co-authored-by: Ben Dwyer <[email protected]>
1 parent 3e6ca5c commit aa17cbd

File tree

1 file changed

+12
-21
lines changed
  • packages/editor/src/components/visual-editor

1 file changed

+12
-21
lines changed

packages/editor/src/components/visual-editor/index.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ import {
1616
privateApis as blockEditorPrivateApis,
1717
__experimentalUseResizeCanvas as useResizeCanvas,
1818
} from '@wordpress/block-editor';
19-
import { useEffect, useRef, useMemo, useState } from '@wordpress/element';
19+
import { useEffect, useRef, useMemo } from '@wordpress/element';
2020
import { useSelect } from '@wordpress/data';
2121
import { parse } from '@wordpress/blocks';
2222
import { store as coreStore } from '@wordpress/core-data';
23-
import {
24-
useMergeRefs,
25-
useViewportMatch,
26-
useResizeObserver,
27-
} from '@wordpress/compose';
23+
import { useMergeRefs, useViewportMatch } from '@wordpress/compose';
2824

2925
/**
3026
* Internal dependencies
@@ -106,10 +102,6 @@ function VisualEditor( {
106102
contentRef,
107103
className,
108104
} ) {
109-
const [ contentHeight, setContentHeight ] = useState( '' );
110-
const effectContentHeight = useResizeObserver( ( [ entry ] ) => {
111-
setContentHeight( entry.borderBoxSize[ 0 ].blockSize );
112-
} );
113105
const isMobileViewport = useViewportMatch( 'small', '<' );
114106
const {
115107
renderingMode,
@@ -326,7 +318,6 @@ function VisualEditor( {
326318
.is-root-container.alignfull { max-width: none; margin-left: auto; margin-right: auto;}
327319
.is-root-container.alignfull:where(.is-layout-flow) > :not(.alignleft):not(.alignright) { max-width: none;}`;
328320

329-
const forceFullHeight = postType === NAVIGATION_POST_TYPE;
330321
const enableResizing =
331322
[
332323
NAVIGATION_POST_TYPE,
@@ -351,7 +342,15 @@ function VisualEditor( {
351342
// Some themes will have `min-height: 100vh` for the root container,
352343
// which isn't a requirement in auto resize mode.
353344
enableResizing ? 'min-height:0!important;' : ''
354-
}}`,
345+
}}
346+
${
347+
enableResizing
348+
? '.block-editor-iframe__html{background:#ddd;display:flex;align-items:center;justify-content:center;min-height:100vh;}.block-editor-iframe__body{width:100%;}'
349+
: ''
350+
}`,
351+
// The CSS above centers the body content vertically when resizing is enabled and applies a background
352+
// color to the iframe HTML element to match the background color of the editor canvas.
353+
// TODO: Move the #ddd somewhere else or use a variable.
355354
},
356355
];
357356
}, [ styles, enableResizing ] );
@@ -369,9 +368,6 @@ function VisualEditor( {
369368
isEnabled: renderingMode === 'template-locked',
370369
} ),
371370
useZoomOutModeExit(),
372-
// Avoid resize listeners when not needed, these will trigger
373-
// unnecessary re-renders when animating the iframe width.
374-
enableResizing ? effectContentHeight : null,
375371
] );
376372

377373
return (
@@ -388,12 +384,7 @@ function VisualEditor( {
388384
}
389385
) }
390386
>
391-
<ResizableEditor
392-
enableResizing={ enableResizing }
393-
height={
394-
contentHeight && ! forceFullHeight ? contentHeight : '100%'
395-
}
396-
>
387+
<ResizableEditor enableResizing={ enableResizing } height="100%">
397388
<BlockCanvas
398389
shouldIframe={ ! disableIframe }
399390
contentRef={ contentRef }

0 commit comments

Comments
 (0)