fix(react-aria): handle position fixed in getTotalOffsetTop to prevent scroll jump#35926
Open
themechbro wants to merge 1 commit intomicrosoft:masterfrom
Open
fix(react-aria): handle position fixed in getTotalOffsetTop to prevent scroll jump#35926themechbro wants to merge 1 commit intomicrosoft:masterfrom
themechbro wants to merge 1 commit intomicrosoft:masterfrom
Conversation
…t scroll jump (fixes microsoft#35921)
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.
Fixes: #35921
When a
DropdownwithinlinePopupis opened inside a scrollable container (like aDialog), a race condition betweencreatePositionManageranduseActiveDescendantcauses the parent container to violently scroll to the top.This occurs because the active descendant controller fires
scrollIntoViewwhile the listbox is still temporarily pinned withposition: fixed. Because fixed elements report anoffsetTopof0, thegetTotalOffsetTopfunction calculates a negative distance, triggering the browser to scroll to the top of the container.The Solution:
Updated the
getTotalOffsetToputility inreact-ariato account for elements removed from the normal document flow.Added a check for
position: fixedusinggetComputedStyle.If the element is fixed, it bypasses the unreliable
offsetTopproperty and instead usesgetBoundingClientRect().topto accurately calculate the visual distance to the scroll parent.Fallbacks to standard
offsetTopmath for all standard relative/absolute elements.Testing:
Verified the math fix resolves the
-111pxscroll jump in the provided reproduction environment without breaking standard relative scroll calculations.