-
Notifications
You must be signed in to change notification settings - Fork 3
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
Recalculate popover position when resized while open #1855
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1855 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 70 70
Lines 1303 1306 +3
Branches 482 482
=========================================
+ Hits 1303 1306 +3 ☔ View full report in Codecov by Sentry. |
351c238
to
8382061
Compare
8382061
to
2ccac98
Compare
@@ -151,6 +165,42 @@ describe('Popover', () => { | |||
}); | |||
}); | |||
|
|||
[true, false].forEach(asNativePopover => { | |||
it('repositions popover if it is resized after being open', async () => { |
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.
This test fails without the observer logic.
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.
@@ -133,9 +133,9 @@ function usePopoverPositioning( | |||
|
|||
// First of all, open popover if it's using the native API, otherwise its | |||
// size is 0x0 and positioning calculations won't work. | |||
const popover = popoverRef.current; | |||
const popover = popoverRef.current!; |
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.
Since this is a local hook I think it is OK to rely on the caller to ensure that popoverRef.current
is set if popoverOpen
is true. If this hook was exposed for consumers of the crate to use, I think we'd need to be more defensive.
This PR fixes an incorrect popover positioning when it gets resized or its contents change while it is open, as the position is calculated only when opened.
With this, we add a
ResizeObserver
which observes the popover, and if it gets resized, we re-calculate its position.The incorrect position usually happens only if the popover had to pop up.
This is how it looks before the fix, when the contents of the popover change after it has been opened:
resize-calculate-2025-01-20_11.54.40.mp4
And this is how it looks once fixed:
resize-calculate-fixed-2025-01-20_11.55.11.mp4
The first time I notice this issue was while working in at-mentions. The suggestions popover content can change while it's open, causing the position to be wrong.
Test steps