-
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
Detect Inserter bounds collision by generic Popover component #1193
Conversation
@aduth Nonetheless increasing the min-height of the overflow element is needed in your implementation to improve it even further. |
components/popover/index.js
Outdated
forcedPositions[ dir ] || ( ! result && includes( positions, dir ) ) | ||
? dir | ||
: result | ||
), null ) || defaultDirection; |
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 think if we store forced positions like this { forceYAxis: 'top', forceXAxis: 'left' }
we could simplify the logic here and avoid some loops.
I really like this generic component, great improvement. I think we should make the arrow optional and use this component for:
Granted this could be done separately. Some notes:
|
Can you clarify the need here? I did find that originally I'd needed to change an |
Yes to all of the above. It should already recompute if position changes. "Size" is hard to measure; maybe children changes? But those changes are difficult (impossible?) to detect (related). |
This simplified things a fair bit. Was able to drop both deep equality check and the |
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.
LGTM 👍 It'd be great to have this merged soon, this is an annoying bug :)
Closes #1098
Closes #1004
This pull request seeks to resolve an issue where the inserter is clipped by the editor bar when opened on a new post. A
Popover
component has been extracted fromInserterMenu
to provide a generic solution to tooltip-like behavior, including boundary collision detection. When the component mounts or its desired position changes, if it exceeds the viewport boundaries, its direction will be flipped.Implementation notes:
Similar to as observed in #839, it is difficult to know from the context of the Popover component the bounds of the editor canvas. In this implementation I merely check whether it exceeds the bounds of the entire page (
top = 0
,left = 0
). This could benefit from extensibility allowing the editor layout to override the default bounds (again, since the component is generic, we should not bind it to the editor use-case).Testing instructions:
Verify that there are no regressions in inserter behavior.
Verify that the editor bar inserter continues to open downward.
Verify that in a post with sufficient content, the inserter opens upward.
Verify that if the inserter were to overlap with the editor bar, it opens downward instead.