fix: floor fractional layout widths to prevent horizontal scrollbar in Virtualizer - #10483
Open
waterWang wants to merge 1 commit into
Open
fix: floor fractional layout widths to prevent horizontal scrollbar in Virtualizer#10483waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
…al scrollbar from fractional container widths When the container width is fractional (e.g. 250.5px), the browser's clientWidth returns an integer that may be rounded up, causing the virtualizer's contentSize.width to be larger than the actual available space. This produces a horizontal scrollbar. Fix: floor the width in contentSize calculation and item rect width computation across ListLayout, GridLayout, WaterfallLayout, and the AI ListLayout, ensuring no layout spills beyond the container. Reference: TableLayout fix adobe#9448 (PR adobe#10238) which used the same Math.floor approach in TableUtils.calculateColumnSizes. Fixes adobe#10471
Member
|
Looks like lint is failing and the CLA maybe hasn't been signed with the e-mail that created this PR. https://github.com/adobe/react-spectrum/blob/main/CONTRIBUTING.md#contributor-license-agreement |
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.
What was changed
When a Virtualizer container has a fractional width (e.g.
250.5px— easily produced by two 50%-width lists side by side), the browser reports an integerclientWidththat can be rounded up. The layouts then setcontentSize.width(and item rect widths) to that larger value, so the content element is wider than the container's real CSS box — producing a horizontal scrollbar.Why it happened
ScrollViewonly appliesoverflow-x: hiddenwhencontentSize.width === state.size.width(the integerclientWidth). When the layout reports a width that was rounded up past the actual CSS width, that equality fails andoverflow: autokicks in.How it's fixed
Floor the width (round down) in the layouts, matching the container's sub-pixel CSS width, so the equality holds and nothing overflows:
ListLayout: floorcontentSize.width/heightplusbuildSection,buildSectionHeader, andbuildItemrect widthsGridLayout: floorcontentSize.widthWaterfallLayout: floorcontentSize.width@react-spectrum/aiListLayout: floorcontentSize.widthThis mirrors the previously merged Table fix (#9448 / PR #10238) which floors
availableWidthinTableUtils.calculateColumnSizes.Tests
Added
ListLayout.test.tsverifying:contentSize.widthis floored when the viewport width is fractional (250.5 → 250)Closes #10471