-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Block Popover: editor canvas as boundary #19322
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,10 +124,14 @@ function BlockPopover( { | |
className="block-editor-block-list__block-popover" | ||
__unstableSticky={ showEmptyBlockSideInserter ? false : popoverIsSticky } | ||
__unstableSlotName="block-toolbar" | ||
__unstableBoundaryParent | ||
// Allow subpixel positioning for the block movement animation. | ||
__unstableAllowVerticalSubpixelPosition={ moverDirection !== 'horizontal' && node } | ||
__unstableAllowHorizontalSubpixelPosition={ moverDirection === 'horizontal' && node } | ||
onBlur={ () => setIsToolbarForced( false ) } | ||
// Popover calculates the width once. Trigger a reset by remounting | ||
// the component. | ||
key={ shouldShowContextualToolbar } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally this shouldn't be needed, but it clashes with the expectation of other popovers with variable height. |
||
> | ||
{ ( shouldShowContextualToolbar || isToolbarForced ) && ( | ||
<div | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,6 +228,7 @@ const Popover = ( { | |
__unstableSlotName = SLOT_NAME, | ||
__unstableAllowVerticalSubpixelPosition, | ||
__unstableAllowHorizontalSubpixelPosition, | ||
__unstableBoundaryParent, | ||
/* eslint-enable no-unused-vars */ | ||
...contentProps | ||
} ) => { | ||
|
@@ -273,14 +274,27 @@ const Popover = ( { | |
contentRect.current = contentRef.current.getBoundingClientRect(); | ||
} | ||
|
||
let boundaryElement; | ||
|
||
if ( __unstableBoundaryParent ) { | ||
boundaryElement = containerRef.current.closest( '.popover-slot' ).parentNode; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a parent element? I mean can we use React context to leverage this instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Store the ref in context? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, that's the idea, it's just a way to avoid making the className an implicit API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason, I cannot get it to work. The context I set around the slot is not available in the popover. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's not a parent. Let's keep it that way then. |
||
} | ||
|
||
const { | ||
popoverTop, | ||
popoverLeft, | ||
xAxis, | ||
yAxis, | ||
contentHeight, | ||
contentWidth, | ||
} = computePopoverPosition( anchor, contentRect.current, position, __unstableSticky, anchorRef ); | ||
} = computePopoverPosition( | ||
anchor, | ||
contentRect.current, | ||
position, | ||
__unstableSticky, | ||
anchorRef, | ||
boundaryElement | ||
); | ||
|
||
if ( typeof popoverTop === 'number' && typeof popoverLeft === 'number' ) { | ||
if ( subpixels && __unstableAllowVerticalSubpixelPosition ) { | ||
|
@@ -374,6 +388,7 @@ const Popover = ( { | |
__unstableSticky, | ||
__unstableAllowVerticalSubpixelPosition, | ||
__unstableAllowHorizontalSubpixelPosition, | ||
__unstableBoundaryParent, | ||
] ); | ||
|
||
useFocusContentOnMount( focusOnMount, contentRef ); | ||
|
@@ -511,6 +526,6 @@ const Popover = ( { | |
const PopoverContainer = Popover; | ||
|
||
PopoverContainer.Slot = ( { name = SLOT_NAME } ) => | ||
<Slot bubblesVirtually name={ name } />; | ||
<Slot bubblesVirtually name={ name } className="popover-slot" />; | ||
|
||
export default PopoverContainer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like we have too many unstable props for the Popover
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah 😅 Soon we should look into rewriting
Popover
or swapping it out, but I'd like to wait for some more simplifications and use cases for positioning.