Repository navigation
feat: rework scroll utilities and fix layout bugs #10556
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
Open
nwidynski
wants to merge
10
commits into
adobe:main
Choose a base branch
from
nwidynski:fix-scrollable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9997478
fix: scrollable flat tree
nwidynski 6bb0942
fix: jsdocs for scroll parent
nwidynski c929ea8
Merge branch 'main' into fix-scrollable
LFDanLu ad3fc75
feat: browser test suite
nwidynski c08058d
fix: ci on linux
nwidynski 5120b05
chore: remove legacy test suite
nwidynski 86e3596
chore: silence ref warn
nwidynski f4410f1
Merge branch 'main' into fix-scrollable
nwidynski f677d2c
Merge branch 'main' into fix-scrollable
nwidynski 2b47244
chore: refactor playwright api
nwidynski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| export class TestContainer { | ||
| private document: Document; | ||
| private window: Window & typeof globalThis; | ||
|
|
||
| constructor(type: string) { | ||
| let doctype = document.implementation.createDocumentType(type, '', ''); | ||
|
|
||
| let iframe = document.createElement('iframe'); | ||
| document.body.append(iframe); | ||
|
|
||
| this.document = iframe.contentDocument as typeof this.document; | ||
| this.window = iframe.contentWindow as typeof this.window; | ||
|
|
||
| this.document.replaceChildren(); | ||
| this.document.append(doctype); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the host node of the container. | ||
| */ | ||
| public getRootNode(): HTMLIFrameElement { | ||
| return this.window.frameElement as HTMLIFrameElement; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the document of the container. | ||
| */ | ||
| public getDocument(): Document { | ||
| return this.document; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the window of the container. | ||
| */ | ||
| public getWindow(): Window & typeof globalThis { | ||
| return this.window; | ||
| } | ||
|
|
||
| /** | ||
| * Clears all nodes in the container document. | ||
| */ | ||
| public reset(): void { | ||
| let doctype = this.document.doctype; | ||
|
|
||
| if (doctype != null) { | ||
| let serializer = new this.window.XMLSerializer(); | ||
| let serialized = serializer.serializeToString(doctype); | ||
|
|
||
| this.document.open(); | ||
| this.document.write(serialized); | ||
| this.document.close(); | ||
| } else { | ||
| this.document.open(); | ||
| this.document.write(''); | ||
| this.document.close(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Removes the container from its owner document. | ||
| */ | ||
| public remove(): void { | ||
| this.window.frameElement?.remove(); | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import {BoundingNode} from './layout'; | ||
|
|
||
| export type Modality = 'keyboard' | 'pointer' | 'virtual'; | ||
|
|
||
| export type ScrollContainer = 'all' | 'nearest'; | ||
| export type ScrollMode = 'always' | 'if-needed'; | ||
|
|
||
| export interface ScrollOptions { | ||
| /** The animation behavior to use for the scroll. */ | ||
| behavior?: ScrollBehavior; | ||
| /** The interaction modality to perform the scroll with. */ | ||
| modality?: Modality; | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export { | ||
| getVisualViewport, | ||
| getWritingElement, | ||
| getStylingElement, | ||
| getScrollingElement, | ||
| getOverflowingElement, | ||
| getContainingElement | ||
| } from '../../../src/utils/layoutHelpers'; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,8 @@ | ||
| export {isWindow, isDocument, isElement, isShadowRoot} from '../../../src/utils/typeHelpers'; | ||
| export { | ||
| isWindow, | ||
| isDocument, | ||
| isElement, | ||
| isHTMLElement, | ||
| isSVGElement, | ||
| isShadowRoot | ||
| } from '../../../src/utils/typeHelpers'; |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| /* | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import {Axis, BoundingNode} from '@react-types/shared'; | ||
| import {getOverflowingElement, getScrollingElement, getWritingElement} from './layoutHelpers'; | ||
| import {getOwnerDocument, getOwnerWindow} from './domHelpers'; | ||
| import {isDocument} from './typeHelpers'; | ||
| import {nodeContains} from './shadowdom/DOMFunctions'; | ||
|
|
||
| export function getScrollLeft(node: BoundingNode): number { | ||
| return getScrollOffset(node, 'inline'); | ||
| } | ||
|
|
||
| export function getScrollTop(node: BoundingNode): number { | ||
| return getScrollOffset(node, 'block'); | ||
| } | ||
|
|
||
| export function getMaxScrollLeft(node: BoundingNode): number { | ||
| return getMaxScrollOffset(node, 'inline'); | ||
| } | ||
|
|
||
| export function getMaxScrollTop(node: BoundingNode): number { | ||
| return getMaxScrollOffset(node, 'block'); | ||
| } | ||
|
|
||
| export function getScrollLeftDirection(node: BoundingNode): 'ascending' | 'descending' { | ||
| return getScrollDirection(node, 'inline'); | ||
| } | ||
|
|
||
| export function getScrollTopDirection(node: BoundingNode): 'ascending' | 'descending' { | ||
| return getScrollDirection(node, 'block'); | ||
| } | ||
|
|
||
| function getScrollOffset(node: BoundingNode, axis: Axis): number { | ||
| let scrollingElement = getScrollingElement(node); | ||
|
|
||
| // TODO: Leave this to each callsite that needs it or force it here? | ||
| // https://issues.chromium.org/issues/40839168 | ||
| // if (isWebKit() && !isIOS() && ownerWindow.devicePixelRatio !== 1) { | ||
| // top = Math.round(scrollOffsetBlock); | ||
| // left = Math.round(scrollOffsetInline); | ||
| // } | ||
|
|
||
| switch (axis) { | ||
| case 'block': | ||
| return scrollingElement.scrollTop; | ||
| case 'inline': | ||
| return scrollingElement.scrollLeft; | ||
| } | ||
| } | ||
|
|
||
| function getMaxScrollOffset(node: BoundingNode, axis: Axis): number { | ||
| let ownerWindow = getOwnerWindow(node); | ||
| let ownerDocument = getOwnerDocument(node); | ||
|
|
||
| let rootScrollingElement = getScrollingElement(ownerDocument); | ||
| let rootOverflowingElement = getOverflowingElement(ownerDocument); | ||
|
|
||
| // A node containing the root scrolling element shall assert as its document. | ||
| if (nodeContains(node, rootScrollingElement)) node = ownerDocument; | ||
|
|
||
| // Overflow on the body and root may be propagated to the viewport, so 'visible' | ||
| // becomes 'auto' and 'clip' turns into 'hidden'. If an element propagates | ||
| // its overflow, its own overflow is always a 'visible' used value, so bail out. | ||
| // https://drafts.csswg.org/css-overflow/#overflow-propagation | ||
| if (node === rootOverflowingElement) return 0; | ||
|
|
||
| let scrollingElement = getScrollingElement(node); | ||
| let overflowingElement = getOverflowingElement(node); | ||
|
|
||
| let style = ownerWindow.getComputedStyle(overflowingElement); | ||
| let [overflowX, overflowY = overflowX] = String(style.overflow).split(' '); | ||
|
|
||
| let isScrollableBlock = /(auto|scroll|hidden)/.test(overflowY + style.overflowY); | ||
| let isScrollableInline = /(auto|scroll|hidden)/.test(overflowX + style.overflowX); | ||
|
|
||
| // Bail if an element is not scrollable in the given axis. | ||
| if (axis === 'block' && !isScrollableBlock && !isDocument(node)) return 0; | ||
| if (axis === 'inline' && !isScrollableInline && !isDocument(node)) return 0; | ||
|
|
||
| // Otherwise, measure the scrollable range in the current direction. | ||
| let scrollSize = axis === 'block' ? scrollingElement.scrollHeight : scrollingElement.scrollWidth; | ||
| let clientSize = axis === 'block' ? scrollingElement.clientHeight : scrollingElement.clientWidth; | ||
|
|
||
| switch (getScrollDirection(node, axis)) { | ||
| case 'ascending': | ||
| return Math.max(0, scrollSize - clientSize); | ||
| case 'descending': | ||
| return Math.min(0, clientSize - scrollSize); | ||
| } | ||
| } | ||
|
|
||
| function getScrollDirection(node: BoundingNode, axis: Axis): 'ascending' | 'descending' { | ||
| let ownerWindow = getOwnerWindow(node); | ||
| let ownerDocument = getOwnerDocument(node); | ||
|
|
||
| let rootScrollingElement = getScrollingElement(ownerDocument); | ||
|
|
||
| // A node containing the root scrolling element shall assert as its document. | ||
| if (nodeContains(node, rootScrollingElement)) node = ownerDocument; | ||
|
|
||
| let writingElement = getWritingElement(node); | ||
| let style = ownerWindow.getComputedStyle(writingElement); | ||
|
|
||
| let isFlexDisplay = /flex/.test(style.display); | ||
| let isFlexReverseBlock = /column-reverse/.test(style.flexDirection); | ||
| let isFlexReverseInline = /row-reverse/.test(style.flexDirection); | ||
|
|
||
| // A viewport is never a flex container, so it only follows the writing direction | ||
| // and any reversed content falls outside of its scrollable overflow region. | ||
| // https://drafts.csswg.org/css-overflow/#scrollable-overflow-region | ||
| if (axis === 'block' && isFlexDisplay && isFlexReverseBlock) { | ||
| return isDocument(node) ? 'ascending' : 'descending'; | ||
| } | ||
|
|
||
| if (axis === 'inline' && isFlexDisplay && isFlexReverseInline && isDocument(node)) { | ||
| return style.direction === 'rtl' ? 'descending' : 'ascending'; | ||
| } | ||
|
|
||
| if (axis === 'inline' && isFlexDisplay && isFlexReverseInline) { | ||
| return style.direction === 'rtl' ? 'ascending' : 'descending'; | ||
| } | ||
|
|
||
| if (axis === 'inline' && style.direction === 'rtl') { | ||
| return 'descending'; | ||
| } | ||
|
|
||
| return 'ascending'; | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.