Skip to content

Commit

Permalink
Site editor: fix padding and margin visualizer positioning (#43971)
Browse files Browse the repository at this point in the history
* Ensure popovers that are in an iframe with their reference element do not receive a frame offset

* Fix comment

* CHANGELOG

* Use refs.floating to gain access to the floating owner document
  • Loading branch information
talldan authored Sep 8, 2022
1 parent 4f7d794 commit 1336026
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- `Popover`: enable auto-updating every animation frame ([#43617](https://github.com/WordPress/gutenberg/pull/43617)).
- `Popover`: improve the component's performance and reactivity to prop changes by reworking its internals ([#43335](https://github.com/WordPress/gutenberg/pull/43335)).
- `NavigatorScreen`: updated to satisfy `react/exhaustive-deps` eslint rule ([#43876](https://github.com/WordPress/gutenberg/pull/43876))
- `Popover`: fix positioning when reference and floating elements are both within an iframe ([#43971](https://github.com/WordPress/gutenberg/pull/43971))

### Enhancements

Expand Down
8 changes: 5 additions & 3 deletions packages/components/src/popover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,12 @@ const UnforwardedPopover = (
// document scrolls. Also update the frame offset if the view resizes.
useLayoutEffect( () => {
if (
// reference and floating are in the same document
// Reference and root documents are the same.
referenceOwnerDocument === document ||
// the reference's document has a view (i.e. window)
// and a frame element (ie. it's an iframe)
// Reference and floating are in the same document.
referenceOwnerDocument === refs?.floating?.current?.ownerDocument ||
// The reference's document has no view (i.e. window)
// or frame element (ie. it's not an iframe).
! referenceOwnerDocument?.defaultView?.frameElement
) {
frameOffsetRef.current = undefined;
Expand Down

0 comments on commit 1336026

Please sign in to comment.