-
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
Make the Popover scrolling and position behavior adapt to the content changes #23159
Conversation
Size Change: +26 B (0%) Total Size: 1.13 MB
ℹ️ View Unchanged
|
508e434
to
fa5395d
Compare
const isMobileViewport = useViewportMatch( 'medium', '<' ); | ||
const [ animateOrigin, setAnimateOrigin ] = useState(); | ||
const slot = useSlot( __unstableSlotName ); | ||
const isExpanded = expandOnMobile && isMobileViewport; | ||
const [ containerResizeListener, contentSize ] = useResizeObserver(); |
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.
I guess we can't use https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver?
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.
Not for the moment (IE11) but this hook is widely used in Gutenberg already and it works pretty well.
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.
We also already have an interval running, so we could use ResizeObserver
and have the interval as a fallback.
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.
Why such complexity while the hook is already there and works properly? I'd rather find a way to remove the interval personally.
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.
Yes, would be great if we could remove the interval
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.
Looks good! I thought this might undo the size adjustments to fit the popover within the viewport, but I see that they're still scrollable.
Requirement for #22789
This PR updates the Popover behavior to make its height adapt to its content and refresh the max-height and position accordingly.
To test this, I added a story to the Popover component where you can increase the height of the popover dynamically.
The inserter popover (used in the canvas inserter) though was incompatible with this behavior. because we can't have both height: 100vh for the popover and have the popover adapts to height at the same time. I adapted the inserter popover styles to fix this.
I'm also pretty sure this PR fixes some dropdown/popover scrolling issues (more menu, block settings). I'll have to retrieve the related tracked issues.
Testing instructions