fix(trigger): keep popup position when trigger element is hidden - #3667
Open
Mowmowj wants to merge 1 commit into
Open
fix(trigger): keep popup position when trigger element is hidden#3667Mowmowj wants to merge 1 commit into
Mowmowj wants to merge 1 commit into
Conversation
When the trigger element becomes display:none while the popup is still visible or fading out (e.g. a hover-revealed icon inside a table row), getBoundingClientRect() measures an all-zero rect and repositioning against it moves the popup to the viewport corner. Skip the reposition and keep the last valid position when the anchor rect is collapsed.
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Types of changes
Background and context
When a trigger element is hidden (e.g.
display: none) while its popup is still visible or fading out, the popup jumps to the top-left corner of the viewport.A common real-world case: a hover-revealed edit icon inside a table row, wrapped in
<a-tooltip>. On mouseleave the row's:hoverstate is lost and the icon becomesdisplay: noneimmediately, while the tooltip is still fading out. Any reposition during that window (onUpdated, resize observer, scroll update) measures the hidden trigger viagetBoundingClientRect(), which returns an all-zero rect, and the popup is moved to the viewport corner.Solution
In
updatePopupStyle(), when not inalignPointmode, skip the reposition and keep the last valid position if the trigger element measures as an all-zero rect (the signature of a hidden element).alignPointmode is unaffected since it positions from the mouse point, not the element rect.How is the change tested?
Added a regression test in
components/trigger/__test__/index.test.ts: mock the trigger'sgetBoundingClientRectwith a real rect, open the popup, then swap the mock to an all-zero rect and force a reposition — the popup style must stay unchanged. The test fails without the fix (popup style becomestop: 0px) and passes with it.Changelog
Checklist:
npm run test)featurebranch and others should be submitted tomainbranch)