Repository navigation
feat(core): add focus-time scroll keyboard delegation - #6301
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
e189c47 to
9ddecd0
Compare
|
/approve-spec 9ddecd0 |
|
/approve-spec 2bb0fff |
9ddecd0 to
2bb0fff
Compare
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsScrollableArea (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 36 accessibility violation(s) found — 2 critical, 34 serious. Button pattern - 1 issue(s)
ChatComposer - 1 issue(s)
ChatComposerInput - 1 issue(s)
ChatReasoning - 1 issue(s)
ChatToolCalls - 1 issue(s)
Checkbox pattern - 1 issue(s)
CheckboxList - 1 issue(s)
ClickableCard - 1 issue(s)
CodeEditor - 1 issue(s)
CodeEditorPerf - 1 issue(s)
CodeEditorTheme - 1 issue(s)
CodeTheme - 1 issue(s)
DateRangeInput - 1 issue(s)
FileInput - 1 issue(s)
GridMasonry - 1 issue(s)
Heading - 1 issue(s)
Icon - 1 issue(s)
LogStream - 1 issue(s)
MediaTheme Auto - 1 issue(s)
PowerSearch - 1 issue(s)
ProgressBar - 1 issue(s)
Radio group pattern - 1 issue(s)
RadioList - 1 issue(s)
RichTextEditor - 2 issue(s)
SelectableCard - 1 issue(s)
Stepper - 1 issue(s)
TableGroupedRows - 1 issue(s)
TableTree - 1 issue(s)
Text - 1 issue(s)
Theme - 1 issue(s)
PopArt - 1 issue(s)
Thumbnail - 1 issue(s)
Timestamp - 1 issue(s)
Token - 1 issue(s)
Tokenizer - 1 issue(s)
Visual RegressionStatus: Skipped — Broad stable scope is deferred to the daily release gate. It covers 386 trusted baseline shots instead of recapturing them for this PR. View the report Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
|
Sorry—I updated your branch without checking with you first. Your BottomSheet work surfaced a useful system-level question: could I explored that direction on this branch, but the continuous observer approach appears too expensive for shared infrastructure. A focus-time, role-aware approach looks more promising. Would you be interested in pushing on that foundational |
|
@cixzhang No worries about the branch update, and thanks for exploring this! I’d be happy to help develop the shared useScrollableArea behavior and use BottomSheet as a proving ground. |
|
Thanks—yes. The interaction model we’re considering is focus-time delegation rather than continuous observation:
The browser proof is part of the implementation, not a prerequisite we expect you to already have. The prototype should demonstrate in Chromium and WebKit:
Would you be interested in prototyping this in |
|
Thanks, this makes the intended behavior much clearer! I’d be happy to prototype it in |
|
@cixzhang The prototype is up in b9aa8e1. The BottomSheet browser fixture passes 48 checks across Chromium 149 and WebKit 26.5, covering all seven requested behaviors plus modal containment, focused overflow loss, horizontal scrolling, and an excluded first target that must not be skipped. The dynamic-content test disconnects mutation observers before changing eligibility and inserting/removing a control. Native Arrow/Page scrolling reaches the full range after delegation. The checked-in reproduction is AST-025 and the existing module contract are updated for this model, so the new head needs owner approval. I’d appreciate your review of the behavior and the conservative eligibility boundary. The independent hardening changes in #6314 remain separate. |
|
Thanks—this is a strong, focused prototype. The current head matches the interaction model we outlined: the viewport remains the named stop, forward entry delegates only to a safe first native action, reverse traversal exits without a loop, and pointer/programmatic focus stay on the viewport. The checked-in browser matrix covers the seven requested behaviors in Chromium and WebKit, plus the horizontal and modal cases. I’m treating the remaining question as owner-level rather than asking you to churn the implementation: this commit also narrows AST-025’s verification matrix from the prior cross-browser requirement to Chromium/WebKit. I’m checking that exact spec change separately. Please hold the current shape while that decision is pending; I’m not asking for branch changes right now. |
|
Owner ruling: accepted. Chromium + WebKit are sufficient as the checked-in native-keyboard proof matrix for this focus-time delegation behavior. This does not narrow AST-025’s compatibility requirement: The current conservative behavior boundary is also accepted: native links/buttons only, excluded composite/navigation-key-owning roles retain the viewport, and BottomSheet remains the proving fixture. |
|
/approve-spec b9aa8e1 |
cixzhang
left a comment
There was a problem hiding this comment.
The focus-time model is strong and the main browser matrix is convincing. I found three bounded issues to fix before merge; none changes the accepted interaction direction.
Owner review determined the remaining observations are rare or trivial and should not block the contributor.
cixzhang
left a comment
There was a problem hiding this comment.
Reviewed exact head b9aa8e1. The focus-time delegation matches the accepted AST-025 direction, the conservative eligibility boundary is appropriate, and the Chromium/WebKit browser evidence covers the user-critical traversal and scrolling behavior.
Resolved conflicts: - packages/core/src/hooks/useScrollableArea.ts: took upstream meta#6301's keyboard delegation (hook-scope hasEffectiveAxis, the attachScrollKeyboardDelegation layout effect, the `contentOrViewport` variant, and the `keyboardAccess.owner !== 'content'` gate with its tabIndex ternary). Dropped this branch's keyboardOwner/keyboardLabel/ keyboardRole scalar extraction, which only handled 'viewport' and would have stripped role, aria-label and tabIndex from `contentOrViewport` adopters such as BottomSheetPanel. Kept the event-based focus tracking by swapping `isViewportFocused` into upstream's keepsProgrammaticFocus, and set the getViewportProps deps to keyboardAccess + isViewportFocused (no viewport). Extended the ScrollKeyboardAccess JSDoc to cover the new variant. (astracat F3) Merge fallout: - packages/core/src/hooks/useScrollableArea.test.tsx: removed the "keeps prop getter identity stable" test. It locked the dropped scalar memoization and the review asked for it to go. (astracat F2, test half)
… claims Addresses astracat-bot's review of meta#6314. F1: ScrollableArea.doc.mjs no longer names `data-scrollable-*` or `data-scroll-*` as presentation hooks. The declared theming surface stays the `astryx-scrollable-area` target with `axis`, which theming.targets already covers, so the whole bestPractices line goes. Stories and tests that probe those attributes stay because they check behavior. Docs-only, so there is no red test. Verified with the ScrollableArea suites, themingTargets.test.ts, check-sync and check-knowledge. F2: the changeset no longer claims that prop getter identity stays stable. The identity-locking test and the scalar memoization it guarded were removed in the upstream merge, since meta#6301's `contentOrViewport` variant conflicted with them. This removes a guarantee, so there is no red test. F3: the retained-tab-stop blur test now runs for both `viewport` and `contentOrViewport` owners. Red: against upstream/main's hook, with no event-based focus tracking, both cases fail at `expect(viewport).not.toHaveAttribute('tabindex')`. Gating keyboardProps on `owner === 'viewport'`, which is the naive PR-side merge resolution, fails the contentOrViewport case at `toHaveAttribute('tabindex', '-1')`. Green: 22/22 in useScrollableArea.test.tsx. 157/157 across the useScrollableArea, scrollKeyboardDelegation, ScrollableArea, BottomSheet, BottomSheetKeyboard and BottomSheetPanel suites.
* fix(ScrollableArea): harden focus and composition Component Hardening Protocol pass over ScrollableArea and useScrollableArea (audited against their current contracts): - getContentProps now consumes caller xstyle instead of leaking it to the DOM as an unknown attribute - viewport focus is tracked with focusin/focusout instead of reading document.activeElement during render; a focused viewport that lost overflow now drops its retained tab stop once blurred - prop getter identity stays stable when adopters pass a fresh keyboardAccess literal each render - removed obsolete -webkit-overflow-scrolling and initial-value scrollbar-width/gutter declarations, and a dead Omit member - tests 24 -> 34: padding precedence and published inset asserted by atomic class (mutation-verified), vacuous overflow assertions tightened, keep-last-state, owner registry unregistration, sideways writing modes, content-getter composition, ARIA conflict wins, and compiled-CSS read-back for the scrollbar token and scroll-state guard - stories: NarrowContainer added; RTLBehaviorProbe and ConditionalKeyboardAccess plays now assert live edge state and the focus-retention path - docs: hook @example, exported type docs, canonical xstyle wording, focus-ring guidance for hook adopters Part of #6306 * docs(ScrollableArea): clarify region vs group choice Consumers get one line of guidance on when role="region" is worth a landmark-navigation entry versus keeping the group default, in both the full and dense doc surfaces. Part of #6306 * test(useScrollableArea): kill zero-size guard mutation The keep-last-state test zeroed only client sizes, so removing the isMeasurable zero-size guard recomputed a state identical to the preserved one and survived the suite. Zeroing every metric of the collapsed box makes an unguarded remeasure publish inactive state, which the assertion now catches. Part of #6306 * test(ScrollableArea): assert scroll-state declaration in block The scroll-state guard test matched only the @supports condition text, so a mutation of the declaration to container-type: inline-size (with the condition left intact) passed. Match the declaration inside the guarded block so a wrong container-type value fails. Part of #6306 * test(ScrollableArea): anchor CSS read-back to the viewport Adversarial preflight confirmed two vacuities in the compiled-CSS tests: the scroll-state assertions were satisfied by the @supports prelude text alone (a mutated inline-size declaration survived), and with runtime injection emitting rules for unused styles, neither test proved the rendered viewport carries the classes (dropping styles.viewport from the composition stayed green). Both tests now match the declaration inside its block and require the owning class on the rendered element. Also corrects the doc guidance attribute prefixes: effective axes are data-scrollable-inline/-block, not data-scroll-*. Part of #6306 * Merge remote-tracking branch 'upstream/main' into rocky/issue-6306-harden-scrollablearea * Merge upstream/main into rocky/issue-6306-harden-scrollablearea Resolved conflicts: - packages/core/src/hooks/useScrollableArea.ts: took upstream #6301's keyboard delegation (hook-scope hasEffectiveAxis, the attachScrollKeyboardDelegation layout effect, the `contentOrViewport` variant, and the `keyboardAccess.owner !== 'content'` gate with its tabIndex ternary). Dropped this branch's keyboardOwner/keyboardLabel/ keyboardRole scalar extraction, which only handled 'viewport' and would have stripped role, aria-label and tabIndex from `contentOrViewport` adopters such as BottomSheetPanel. Kept the event-based focus tracking by swapping `isViewportFocused` into upstream's keepsProgrammaticFocus, and set the getViewportProps deps to keyboardAccess + isViewportFocused (no viewport). Extended the ScrollKeyboardAccess JSDoc to cover the new variant. (astracat F3) Merge fallout: - packages/core/src/hooks/useScrollableArea.test.tsx: removed the "keeps prop getter identity stable" test. It locked the dropped scalar memoization and the review asked for it to go. (astracat F2, test half) * fix(ScrollableArea): drop unpromised styling-hook and getter-identity claims Addresses astracat-bot's review of #6314. F1: ScrollableArea.doc.mjs no longer names `data-scrollable-*` or `data-scroll-*` as presentation hooks. The declared theming surface stays the `astryx-scrollable-area` target with `axis`, which theming.targets already covers, so the whole bestPractices line goes. Stories and tests that probe those attributes stay because they check behavior. Docs-only, so there is no red test. Verified with the ScrollableArea suites, themingTargets.test.ts, check-sync and check-knowledge. F2: the changeset no longer claims that prop getter identity stays stable. The identity-locking test and the scalar memoization it guarded were removed in the upstream merge, since #6301's `contentOrViewport` variant conflicted with them. This removes a guarantee, so there is no red test. F3: the retained-tab-stop blur test now runs for both `viewport` and `contentOrViewport` owners. Red: against upstream/main's hook, with no event-based focus tracking, both cases fail at `expect(viewport).not.toHaveAttribute('tabindex')`. Gating keyboardProps on `owner === 'viewport'`, which is the naive PR-side merge resolution, fails the contentOrViewport case at `toHaveAttribute('tabindex', '-1')`. Green: 22/22 in useScrollableArea.test.tsx. 157/157 across the useScrollableArea, scrollKeyboardDelegation, ScrollableArea, BottomSheet, BottomSheetKeyboard and BottomSheetPanel suites. * fix(useScrollableArea): track viewport focus in the callback ref Addresses astracat-bot's review of #6314. The viewport ref already runs on attach, detach and replacement, and mergeRefs passes React 19 ref cleanups through. The ref now adopts the current focus from the viewport's own document, adds focusin and focusout listeners, and returns a cleanup that removes them and resets the focus and viewport state. That drops the extra layout effect and its set-state-in-effect suppression. Reading the owner document keeps a focused viewport in an iframe focusable when it loses overflow. Focus events do not always reach the viewport: Chromium fires none while the page lacks system focus, and an ancestor can stop them. A measurement that finds no scrollable axis therefore reads focus too. Only a viewport with no scrollable axis reads that state, so the listeners and the measurement skip it while an axis scrolls; otherwise each focus change re-rendered the host, which is costly on lab Schedule's time grid. Until an axis change is measured, the last measured scrolling keeps a focused viewport's tabindex, because dropping it in that first commit blurs the viewport in Chromium. Tests: the focus lifecycle (StrictMode replay, same-commit replacement, detach, fresh caller refs, descendants, same-task focus hops, stopped focus events, axis changes, commit counts while scrolling), padding and inset variables on every edge, exact scrollbar and overflow values, and an unmeasurable test that now exercises a full measurement. All 25 hook mutations are caught. Also reverts a no-op `children` Omit edit, corrects two story comments, and rewrites the changeset. Part of #6306 * Merge upstream/main into rocky/issue-6306-harden-scrollablearea CI's build job checks out the PR head and runs .github/scripts/build-packages-and-storybook.mjs, which landed on main after this branch's base. * Merge remote-tracking branch 'origin/main' into rocky/issue-6306-harden-scrollablearea # Conflicts: # packages/core/src/hooks/useScrollableArea.test.tsx * docs(ScrollableArea): the role guidance says to leave role unset rather than restating the default Co-authored-by: AK <[email protected]> Co-authored-by: Cindy Zhang <[email protected]>
User need
Fixes #5207. Keyboard users need to reach every part of overflowing BottomSheet content, including text-only sheets, without an unnecessary viewport stop before a safe existing action.
Problem and solution fit
This prototypes the shared focus-time delegation model discussed in #6301 (comment).
useScrollableAreakeeps the overflowing viewport named and tabbable, inspects the first sequential descendant on forward Tab entry, and delegates only to a native link or button whose context preserves native scroll keys.A first input or custom/composite target is never skipped to find a later button. Composite/navigation roles, editable surfaces, popup triggers, positive tab ordering, and native or registered nested scroll owners retain the viewport stop. Shift+Tab from the delegated first child skips the viewport, including after visiting later children. Pointer and programmatic focus remain on the viewport.
Eligibility is recalculated on the next keyboard entry. Keyboard-specific subtree/ancestor observation and the persistent focusability state are removed. Existing geometry observation remains separate, with its original attribute filters. Scrolling stays native.
Current specification
The canonical owners remain
spec:AST-025andmodule:ScrollableArea/useScrollableArea. Their existing automatic-access records and BottomSheet's draft contract are updated for review; the new head needs owner approval before merging.Public delta and caller burden
The PR adds the shared
contentOrViewportkeyboard ownership mode. Existingcontentandviewportmodes remain available. BottomSheet adopts the shared hook without adding public BottomSheet props or exports:The real flow-root content box preserves the existing block/percentage-height layout evidence. Sheet-local Sticky containment stays explicit. Consumers keep their own content names inside the named viewport.
Design and alternatives
Continuous focusability observation was explored earlier on this branch. The prototype replaces that cost with one entry-time eligibility check, using a conservative native link/button boundary. It does not introduce JavaScript scrolling or an additional caller configuration surface.
Evidence
The checked-in
Core/BottomSheet → Keyboard Delegationstory andBottomSheetKeyboard.a11y.browser.spec.tscover:macOS WebKit's all-controls traversal uses Option+Tab. Its existing non-modal dialog host is a separate native stop, and its native boundary feedback may overshoot an edge. The tests preserve those platform behaviors.
Scope
Testing
pnpm build: passed.pnpm lint:strict: passed with existing warnings and no errors.pnpm check:knowledge: passed.pnpm test --maxWorkers=2: 17,005 passed; the restricted local run also reported 38 failures in 14 tooling suites. Rerunning all failed suites with network/cache access cleared the environment failures. Four unchanged failures remain: two setup-workspace cases requiring GNUcp --reflinkon macOS, and two existing Storybook title-classification assertions. None is in the changed scroll/BottomSheet code.Reproduce the browser proof after
pnpm storybook:buildandpnpm exec playwright install chromium webkit:pnpm test:a11y-contractremains scoped to Chromium so the existing CI lane does not start requiring an uninstalled WebKit browser.