refactor(segmentedcontrol): use shared useListFocus instead of inline roving#3485
Draft
cixzhang wants to merge 1 commit into
Draft
refactor(segmentedcontrol): use shared useListFocus instead of inline roving#3485cixzhang wants to merge 1 commit into
cixzhang wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
josephfarina
approved these changes
Jul 3, 2026
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
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.
Summary
Refactors
SegmentedControlto delegate its roving-tabindex and arrow-key navigation to the shareduseListFocusprimitive (hasRovingTabIndex: true), removing ~60 lines of duplicated inline logic. No behavior change — all existing tests pass unmodified.What changed
Before,
SegmentedControlhand-rolled:handleKeyDownwithArrowLeft/ArrowRight/Home/End, wrap, disabled-skip, and selection-follows-focus (callingonChangeon every move).useIsomorphicLayoutEffecttab-stop repair that queried[role="radio"]:not([aria-disabled="true"])and promoted the first enabled radio totabIndex=0when none was tabbable.After, that is replaced by:
useListFocusnow owns the single roving tab stop (stampstabIndex0/-1, skips disabled radios, wraps, handles Home/End, and repairs the stop on mount/disable).Selection-follows-focus (APG radiogroup) is preserved with a slim container
onFocushandler.useListFocusonly moves focus; the handler reads the newly-focused radio'sdata-valueand callsonChange— keeping selection in lockstep with focus without duplicating navigation logic. It ignores disabled radios and skips the already-selected value (so an initial Tab-in / click on the current segment is a no-op, matching click behavior).SegmentedControlItemis unchanged: it keepstabIndex={isSelected && !isItemDisabled ? 0 : -1}as the source-of-truth hint.useListFocus's repair preserves an existing0and only repairs when none is tabbable.Net line count
SegmentedControl.tsx: +33 / −76 (net −43 lines).Verification
pnpm -F @astryxdesign/core typecheck— exit 0npx eslinton both changed files — clean (exit 0)npx vitest run packages/core/src/SegmentedControl— 23/23 pass (arrow nav + select, wrap both directions, Home/End, disabled-skip, roving tabindex assertions, tab-stop repair for unmatched value, first-enabled promotion when first is disabled, disabled-group no tab stop, individually-disabled selected item no tab stop)Changeset
@astryxdesign/corepatch,[refactor].