-
Couldn't load subscription status.
- Fork 201
fix: Fixes popover position recomputation for charts #3958
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
base: main
Are you sure you want to change the base?
Conversation
| // Recalculate position when the DOM changes. | ||
| // istanbul ignore next - tested via integration tests | ||
| usePositionObserver(trackRef, trackKey, () => { | ||
| usePositionObserver(getTrack.current, trackKey, () => { |
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.
getTrack.current represents one of the two supported ways to provide the track element, the second one is used by the charts components.
| const popoverOffset = popoverRef.current && getLogicalBoundingClientRect(popoverRef.current); | ||
|
|
||
| if ( | ||
| keepPosition || |
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 only use keepPosition=true in charts. The need of preventing the position update in this case is not clear though: when a layout shift occurs, the chart popover can be misplaced, too.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3958 +/- ##
=======================================
Coverage 97.17% 97.17%
=======================================
Files 854 854
Lines 24983 24983
Branches 8803 8802 -1
=======================================
Hits 24276 24276
- Misses 659 701 +42
+ Partials 48 6 -42 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
067d5b6 to
08028b7
Compare
08028b7 to
1c41577
Compare
1c41577 to
4250433
Compare
4250433 to
f90c0a8
Compare
f90c0a8 to
da6b352
Compare
Description
The popover includes code that should recompute its position when there is a layout shift on the page, e.g. when a split-panel opens, causing the popover target to change. The keepPosition property is only used for charts popover, and for some reason the popovers with keepPosition=true were not updated. However, this causes the charts popover position to be off if the layout shift occurs.
See how legacy charts reacted to a split panel open before the change:
Screen.Recording.2025-10-22.at.14.06.33.mov
With the change (removing keepPosition check), the popover position is correctly adjusted.
Screen.Recording.2025-10-22.at.14.07.30.mov
The fix only works well when the layout change does not cause the chart to change size. If that happens, then the popover (even if pinned) is closed in area- and pie charts. In mixed charts (incl. bar- and line charts, too), the popover is not closed, but the track marker is not updated, causing both the marker and the popover to have incorrect position. That is an existing bug, reproducible with both old and new code, and it is not addressed by this change.
Screen.Recording.2025-10-22.at.14.11.29.mov
The fix also works in the new cartesian and pie charts. There, the positions of the tooltip and the marker are correctly recomputed.
Screen.Recording.2025-10-22.at.14.12.57.mov
Rel: AWSUI-61377
How has this been tested?
Review checklist
The following items are to be evaluated by the author(s) and the reviewer(s).
Correctness
CONTRIBUTING.md.CONTRIBUTING.md.Security
checkSafeUrlfunction.Testing
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.