Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popover: anchor correctly to parent node when no explicit anchor is passed #42971

Merged
merged 5 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const ImageURLInputUI = ( {
rel,
} ) => {
const [ isOpen, setIsOpen ] = useState( false );
const buttonRef = useRef( null );
const openLinkUI = useCallback( () => {
setIsOpen( true );
} );
Expand Down Expand Up @@ -245,9 +246,11 @@ const ImageURLInputUI = ( {
label={ url ? __( 'Edit link' ) : __( 'Insert link' ) }
aria-expanded={ isOpen }
onClick={ openLinkUI }
ref={ buttonRef }
/>
{ isOpen && (
<URLPopover
anchorRef={ buttonRef }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing an explicit anchorRef here so that the URL popover is anchored to the button (and not to the whole toolbar).

onFocusOutside={ onFocusOutside() }
onClose={ closeLinkUI }
renderSettings={ () => advancedOptions }
Expand Down
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`: fix arrow placement and design ([#42874](https://github.com/WordPress/gutenberg/pull/42874/)).
- `Popover`: fix minor glitch in arrow [#42903](https://github.com/WordPress/gutenberg/pull/42903)).
- `ToolsPanel`: Constrain grid columns to 50% max-width ([#42795](https://github.com/WordPress/gutenberg/pull/42795)).
- `Popover`: anchor correctly to parent node when no explicit anchor is passed ([#42971](https://github.com/WordPress/gutenberg/pull/42971)).

### Enhancements

Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ const Popover = (
},
};
} else if ( anchorRefFallback.current ) {
resultingReferenceRef = anchorRefFallback.current;
// If no explicit ref is passed via props, fall back to
// anchoring to the popover's parent node.
resultingReferenceRef = anchorRefFallback.current.parentNode;
}

if ( ! resultingReferenceRef ) {
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/popover/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ $arrow-triangle-base-size: 14px;
width: $arrow-triangle-base-size;
height: $arrow-triangle-base-size;
pointer-events: none;
display: flex;

// Thin line that helps to make sure that the underlying
// popover__content's outline is fully overlapped by the
Expand Down Expand Up @@ -103,9 +104,8 @@ $arrow-triangle-base-size: 14px;
}

.components-popover__triangle {
position: absolute;
height: 100%;
width: 100%;
display: block;
flex: 1;
}

.components-popover__triangle-bg {
Expand Down