diff --git a/packages/components/src/popover/index.js b/packages/components/src/popover/index.js index b0e8d4bccb7a3..616181a38e85d 100644 --- a/packages/components/src/popover/index.js +++ b/packages/components/src/popover/index.js @@ -47,7 +47,8 @@ function computeAnchorRect( anchorRect, getAnchorRect, anchorRef = false, - shouldAnchorIncludePadding + shouldAnchorIncludePadding, + container ) { if ( anchorRect ) { return anchorRect; @@ -61,7 +62,8 @@ function computeAnchorRect( const rect = getAnchorRect( anchorRefFallback.current ); return offsetIframe( rect, - rect.ownerDocument || anchorRefFallback.current.ownerDocument + rect.ownerDocument || anchorRefFallback.current.ownerDocument, + container ); } @@ -81,7 +83,8 @@ function computeAnchorRect( if ( typeof anchorRef?.cloneRange === 'function' ) { return offsetIframe( getRectangleFromRange( anchorRef ), - anchorRef.endContainer.ownerDocument + anchorRef.endContainer.ownerDocument, + container ); } @@ -91,7 +94,8 @@ function computeAnchorRect( if ( typeof anchorRef?.getBoundingClientRect === 'function' ) { const rect = offsetIframe( anchorRef.getBoundingClientRect(), - anchorRef.ownerDocument + anchorRef.ownerDocument, + container ); if ( shouldAnchorIncludePadding ) { @@ -111,7 +115,8 @@ function computeAnchorRect( topRect.width, bottomRect.bottom - topRect.top ), - top.ownerDocument + top.ownerDocument, + container ); if ( shouldAnchorIncludePadding ) { @@ -294,7 +299,8 @@ const Popover = ( anchorRect, getAnchorRect, anchorRef, - shouldAnchorIncludePadding + shouldAnchorIncludePadding, + containerRef.current ); if ( ! anchor ) { diff --git a/packages/components/src/popover/test/utils.js b/packages/components/src/popover/test/utils.js index 4b6c015585f49..3d6b3a8358db6 100644 --- a/packages/components/src/popover/test/utils.js +++ b/packages/components/src/popover/test/utils.js @@ -296,7 +296,7 @@ describe( 'offsetIframe', () => { } ) ); const rect = child.getBoundingClientRect(); - const offsettedRect = offsetIframe( rect, child.ownerDocument ); + const offsettedRect = offsetIframe( rect, child.ownerDocument, parent ); expect( offsettedRect.left ).toBe( iframeLeft + childLeft ); expect( offsettedRect.top ).toBe( iframeTop + childTop ); diff --git a/packages/components/src/popover/utils.js b/packages/components/src/popover/utils.js index cedaa5466dd04..3d23ae71fb211 100644 --- a/packages/components/src/popover/utils.js +++ b/packages/components/src/popover/utils.js @@ -328,19 +328,22 @@ export function computePopoverPosition( } /** - * Offsets the given rect by the position of the iframe that contains the element. - * If the owner document is not in an iframe then it returns with the original rect. + * Offsets the given rect by the position of the iframe that contains the + * element. If the owner document is not in an iframe then it returns with the + * original rect. If the popover container document and the anchor document are + * the same, the original rect will also be returned. * - * @param {DOMRect} rect bounds of the element + * @param {DOMRect} rect bounds of the element * @param {Document} ownerDocument document of the element + * @param {Element} container The popover container to position. * * @return {DOMRect} offsetted bounds */ -export function offsetIframe( rect, ownerDocument ) { +export function offsetIframe( rect, ownerDocument, container ) { const { defaultView } = ownerDocument; const { frameElement } = defaultView; - if ( ! frameElement ) { + if ( ! frameElement || ownerDocument === container.ownerDocument ) { return rect; } diff --git a/packages/edit-navigation/src/components/layout/index.js b/packages/edit-navigation/src/components/layout/index.js index 9be2cfa8c6bd2..76565e85a1d5d 100644 --- a/packages/edit-navigation/src/components/layout/index.js +++ b/packages/edit-navigation/src/components/layout/index.js @@ -163,19 +163,19 @@ export default function Layout( { blockEditorSettings } ) { /> ) } { isBlockEditorReady && ( - -
+
+ -
- + +
) } } diff --git a/packages/edit-navigation/src/components/layout/style.scss b/packages/edit-navigation/src/components/layout/style.scss index 6f766e33e635b..9689f2ecc1385 100644 --- a/packages/edit-navigation/src/components/layout/style.scss +++ b/packages/edit-navigation/src/components/layout/style.scss @@ -31,6 +31,9 @@ } .edit-navigation-layout__content-area { + // Reference element for the block popover position. + position: relative; + // The 10px match that of similar settings pages. padding: $grid-unit-15 10px 10px 10px; diff --git a/packages/edit-widgets/src/components/widget-areas-block-editor-content/index.js b/packages/edit-widgets/src/components/widget-areas-block-editor-content/index.js index dd8cddb1401e5..98314922af62b 100644 --- a/packages/edit-widgets/src/components/widget-areas-block-editor-content/index.js +++ b/packages/edit-widgets/src/components/widget-areas-block-editor-content/index.js @@ -21,20 +21,22 @@ export default function WidgetAreasBlockEditorContent( { blockEditorSettings, } ) { return ( - - - +
-
- - - - - - - - -
- + + + +
+ + + + + + + + +
+
+
); } diff --git a/storybook/stories/playground/index.js b/storybook/stories/playground/index.js index d87fb3907bbde..171034d1161e4 100644 --- a/storybook/stories/playground/index.js +++ b/storybook/stories/playground/index.js @@ -38,17 +38,19 @@ function App() {
- -
- - - - - - - -
-
+
+ +
+ + + + + + + +
+
+
diff --git a/storybook/stories/playground/style.scss b/storybook/stories/playground/style.scss index ee7da78f7ff0b..af3cf09dd36c7 100644 --- a/storybook/stories/playground/style.scss +++ b/storybook/stories/playground/style.scss @@ -24,6 +24,11 @@ } } +.playground__content { + // Reference element for the block popover position. + position: relative; +} + .playground__sidebar { position: fixed; top: 0;