Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(SegmentedControl): a disabled control, or a disabled selected segment, keeps the Tab stop (#9314)

Cindy Zhang432d9577d195
diff --git a/.changeset/segmented-control-disabled-tab-stop.md b/.changeset/segmented-control-disabled-tab-stop.md
new file mode 100644
index 0000000000..aa65d81f32
--- /dev/null
+++ b/.changeset/segmented-control-disabled-tab-stop.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] SegmentedControl: a disabled control, or a disabled selected segment, keeps the control's Tab stop. Before, a control disabled without a `disabledMessage` had no Tab stop and ignored the pointer. A selected segment that was itself disabled lost the stop to another segment, and once the stop had moved there, selecting a third segment left it behind, so Tab re-entered on an unchecked segment. Now the selected segment always holds the one Tab stop, announced as disabled (`aria-disabled`) when it is, and nothing can be selected while disabled.
+
+@cixzhang
diff --git a/docs/specs/components/SegmentedControl/SegmentedControl.spec.md b/docs/specs/components/SegmentedControl/SegmentedControl.spec.md
index 2623e01b3b..c5b26a983f 100644
--- a/docs/specs/components/SegmentedControl/SegmentedControl.spec.md
+++ b/docs/specs/components/SegmentedControl/SegmentedControl.spec.md
@@ -49,15 +49,15 @@ system_specs: [spec:AST-020, spec:AST-085]
## Contract at a glance
-| Area | Contract |
-| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
-| Public contract | None changes. SegmentedControl takes `label`, `value`, `onChange`, `size`, `layout`, `isDisabled`, `disabledMessage`, base props, and SegmentedControlItem children. |
-| Behavior | A `role="radiogroup"` named by `label` with one Tab stop; arrow keys, Home, and End move focus between enabled segments, wrap, and select the segment they land on. Tabbing in never changes the value. |
-| End-user impact | People switch between a few modes with one click or arrow press, and the control shrinks with its row by truncating labels. A disabled control without a reason drops out of the tab order. |
-| Builder impact | None. |
-| Compatibility/readiness | Records shipped behavior; no API, default, or DOM change. A disabled selected segment loses the Tab stop, a disabled control can have no Tab stop, a press while focused selects before any click, a caller `onFocus` or `onBlur` can cancel built-in focus behavior, caller handlers run while disabled, and a caller `aria-describedby` is dropped; all are listed under Current-state impact. |
-| Review checks | Reject more than one Tab stop, a value change on Tab entry, arrows that land on a disabled segment, a control that overflows its container when segments have labels, or a selection while disabled. |
-| Governing rules | WAI-ARIA radio group pattern; `spec:AST-020` FR9, FR15, DEC-5; `spec:AST-085` FR1, FR2, FR5, FR7; `design:user-states` DR1–DR3 (through SegmentedControlItem); `design:bidirectionality` DR6; `architecture:component-size-cascade` INV3–INV5; `architecture:interaction-modality` INV1; `architecture:public-component-api` INV5, INV7. |
+| Area | Contract |
+| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| Public contract | None changes. SegmentedControl takes `label`, `value`, `onChange`, `size`, `layout`, `isDisabled`, `disabledMessage`, base props, and SegmentedControlItem children. |
+| Behavior | A `role="radiogroup"` named by `label` with one Tab stop; arrow keys, Home, and End move focus between enabled segments, wrap, and select the segment they land on. Tabbing in never changes the value. |
+| End-user impact | People switch between a few modes with one click or arrow press, and the control shrinks with its row by truncating labels. A disabled control keeps one Tab stop. |
+| Builder impact | None. |
+| Compatibility/readiness | Records shipped behavior; no API, default, or DOM change. A press while focused selects before any click, a caller `onFocus` or `onBlur` can cancel built-in focus behavior, caller handlers run while disabled, and a caller `aria-describedby` is dropped; all are listed under Current-state impact. |
+| Review checks | Reject more than one Tab stop, a value change on Tab entry, arrows that land on a disabled segment, a control that overflows its container when segments have labels, or a selection while disabled. |
+| Governing rules | WAI-ARIA radio group pattern; `spec:AST-020` FR9, FR15, DEC-5; `spec:AST-085` FR1, FR2, FR5, FR7; `design:user-states` DR1–DR3 (through SegmentedControlItem); `design:bidirectionality` DR6; `architecture:component-size-cascade` INV3–INV5; `architecture:interaction-modality` INV1; `architecture:public-component-api` INV5, INV7. |
This table is a review projection; the body below is authoritative.
@@ -112,16 +112,16 @@ Consumer migration instructions belong in consumer docs and release notes.
## Behavioral and layout contract
-| ID | Invariant | Basis |
-| --- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
-| FR1 | The radiogroup container carries the current `segmented-control` target with `data-size`, sets `aria-label` to `label`, and renders its supplied children. | Current source, docs, and tests |
-| FR2 | The group is one Tab stop: the selected segment, or, when the value matches no segment, the first segment not disabled by its own `isDisabled` (in a disabled group that segment keeps the stop, FR7); a disabled selected segment MUST keep the Tab stop (`spec:AST-085` FR1). Implementation gap: when the selected segment is disabled, the first enabled segment takes the Tab stop; and once the stop has fallen back to the first enabled segment, selecting another segment by click or by `value` leaves the stop there, so Tab re-enters on an unchecked segment. ArrowLeft and ArrowRight move focus between enabled segments in the visual direction, flipping in right-to-left layouts (`design:bidirectionality` DR6), and wrap; Home and End jump to the ends; ArrowUp and ArrowDown do nothing. Disabled segments are skipped. | WAI-ARIA radio group pattern; current tests; `design:bidirectionality` DR6 |
-| FR3 | When arrow, Home, or End navigation moves focus to an enabled segment, that segment's value is passed to `onChange` if it differs. A pointer press MUST select only on a click whose lift lands inside the segment (`spec:AST-020` FR9, DEC-5). Implementation gap: while focus is already in the group, a pointer press on another segment moves focus there and selects before any click, so a press that slides off still selects. Focus entering the group from outside never changes the value. | WAI-ARIA radio group pattern; current tests; `spec:AST-020` FR9, DEC-5 |
-| FR4 | A caller `onKeyDown` runs before built-in navigation and can cancel it with `preventDefault()`; a caller `onFocus` runs before selection-follows-focus. On first keyboard focus an ephemeral hint naming the arrow keys appears at the focused segment and dismisses on the first arrow press, a timeout, or blur. Built-in focus behavior MUST NOT be cancellable except where the public API promises it (`architecture:public-component-api` INV7). Implementation gap: a caller `onFocus` that calls `preventDefault()` also cancels the hint, the Tab-stop sync, and selection-follows-focus, and a caller `onBlur` that does so cancels the hint's blur dismissal. | Current source and tests; `architecture:public-component-api` INV7 |
-| FR5 | `hug` sizes the control to its segments; when any segment shows a visible label, the control never exceeds its container and labelled segments shrink and truncate. A control of only icon-only segments keeps its size. `fill` stretches the control to its container and gives segments equal shares that can shrink and truncate. | Current tests |
-| FR6 | Size resolves from an explicit `size`, then the nearest size provider, then `md`, and reaches every segment. | `architecture:component-size-cascade` INV3–INV5; current source |
-| FR7 | `isDisabled` sets `aria-disabled` on the radiogroup, disables every segment, dims the control to half opacity, and blocks selection. The group MUST keep a Tab stop while disabled (`spec:AST-085` FR1, FR7). With `disabledMessage`, the selected segment stays the Tab stop, pointer events stay on, and a reason tooltip opens on hover and keyboard focus; the reason MUST describe the focusable segment (`spec:AST-085` FR5, FR7). Implementation gap: caller handlers on the radiogroup, such as `onKeyDown`, still run while disabled (`spec:AST-085` FR2); and without a `disabledMessage` the group ignores pointer input and every segment leaves the tab order, so the control has no Tab stop. | `spec:AST-085`; current tests |
-| FR8 | The radiogroup owns `role`, `aria-label` (from `label`), `aria-disabled`, and `data-size`; a caller value for any of them is replaced. Other base props reach the radiogroup, and `ref` reaches it. Implementation gap: a caller `aria-describedby` is replaced, by the disabled-reason id or by nothing, against `architecture:public-component-api` INV5. | `architecture:public-component-api` INV5; current source and tests |
+| ID | Invariant | Basis |
+| --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------- |
+| FR1 | The radiogroup container carries the current `segmented-control` target with `data-size`, sets `aria-label` to `label`, and renders its supplied children. | Current source, docs, and tests |
+| FR2 | The group is one Tab stop: the selected segment, or, when the value matches no segment, the first segment not disabled by its own `isDisabled` (in a disabled group that segment keeps the stop, FR7); a disabled selected segment MUST keep the Tab stop (`spec:AST-085` FR1). ArrowLeft and ArrowRight move focus between enabled segments in the visual direction, flipping in right-to-left layouts (`design:bidirectionality` DR6), and wrap; Home and End jump to the ends; ArrowUp and ArrowDown do nothing. Disabled segments are skipped. | WAI-ARIA radio group pattern; current tests; `design:bidirectionality` DR6 |
+| FR3 | When arrow, Home, or End navigation moves focus to an enabled segment, that segment's value is passed to `onChange` if it differs. A pointer press MUST select only on a click whose lift lands inside the segment (`spec:AST-020` FR9, DEC-5). Implementation gap: while focus is already in the group, a pointer press on another segment moves focus there and selects before any click, so a press that slides off still selects. Focus entering the group from outside never changes the value. | WAI-ARIA radio group pattern; current tests; `spec:AST-020` FR9, DEC-5 |
+| FR4 | A caller `onKeyDown` runs before built-in navigation and can cancel it with `preventDefault()`; a caller `onFocus` runs before selection-follows-focus. On first keyboard focus an ephemeral hint naming the arrow keys appears at the focused segment and dismisses on the first arrow press, a timeout, or blur. Built-in focus behavior MUST NOT be cancellable except where the public API promises it (`architecture:public-component-api` INV7). Implementation gap: a caller `onFocus` that calls `preventDefault()` also cancels the hint, the Tab-stop sync, and selection-follows-focus, and a caller `onBlur` that does so cancels the hint's blur dismissal. | Current source and tests; `architecture:public-component-api` INV7 |
+| FR5 | `hug` sizes the control to its segments; when any segment shows a visible label, the control never exceeds its container and labelled segments shrink and truncate. A control of only icon-only segments keeps its size. `fill` stretches the control to its container and gives segments equal shares that can shrink and truncate. | Current tests |
+| FR6 | Size resolves from an explicit `size`, then the nearest size provider, then `md`, and reaches every segment. | `architecture:component-size-cascade` INV3–INV5; current source |
+| FR7 | `isDisabled` sets `aria-disabled` on the radiogroup, disables every segment, dims the control to half opacity, and blocks selection. The group MUST keep a Tab stop while disabled, placed as in FR2, and pointer events stay on (`spec:AST-085` FR1, FR7). With `disabledMessage`, a reason tooltip opens on hover and keyboard focus; the reason MUST describe the focusable segment (`spec:AST-085` FR5, FR7). Implementation gap: caller handlers on the radiogroup, such as `onKeyDown`, still run while disabled (`spec:AST-085` FR2). | `spec:AST-085`; current tests |
+| FR8 | The radiogroup owns `role`, `aria-label` (from `label`), `aria-disabled`, and `data-size`; a caller value for any of them is replaced. Other base props reach the radiogroup, and `ref` reaches it. Implementation gap: a caller `aria-describedby` is replaced, by the disabled-reason id or by nothing, against `architecture:public-component-api` INV5. | `architecture:public-component-api` INV5; current source and tests |
### Allowed variation
@@ -138,7 +138,7 @@ Consumer migration instructions belong in consumer docs and release notes.
| Fill | Full width; equal segments. | — |
| Unmatched value | The first segment not disabled by its own `isDisabled` is the Tab stop; Tab-in changes nothing. | — |
| Disabled with reason | Selected segment focusable; reason tooltip; no selection. | — |
-| Disabled, no reason | No selection. Implementation gap: no Tab stop (FR7). | — |
+| Disabled, no reason | Selected segment focusable; no selection. | — |
### Transformation and precedence order
@@ -147,10 +147,9 @@ Consumer migration instructions belong in consumer docs and release notes.
sync, and selection-follows-focus (today also cancelled by a prevented
`onFocus`, FR4 gap).
- **ORD2 — Tab stop.** The selected segment; for a value that matches no
- segment, the first segment not disabled by its own `isDisabled`. Today a
- disabled selected segment keeps the stop only in a group disabled with a
- reason, and a fallen-back stop stays on the first enabled segment after
- another segment is selected (FR2, FR7 gaps).
+ segment, the first segment not disabled by its own `isDisabled`. A disabled
+ selected segment, or a segment of a disabled control, keeps the stop (FR2,
+ FR7).
### Performance and resources
@@ -201,34 +200,26 @@ segment parts as well.
- `architecture:component-theming-surface` owns anatomy qualification, inherited
parts, and state-on-target rules.
- `spec:AST-085` owns disabled focusability, reasons, and callbacks; FR7
- records the gaps.
+ records the gap.
- `component:SegmentedControlItem` owns each segment.
## Verification map
-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
-| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------- |
-| FR1, AR1 | `SegmentedControl.test.tsx` rendering, size, and data-testid cases; `RadioGroup.a11y.test.tsx` and `RadioGroup.a11y.chromium.spec.ts` (in `RadioList/__tests__`) `segmented-group-*` states | Control with several segments; sizes | Lost group semantics or name fails. Evidence gap: no test asserts the `segmented-control` target or `data-size`. | `audit:SegmentedControl/anatomy` |
-| FR2, FR3, ORD2, AR2 | `SegmentedControl.test.tsx` keyboard-navigation and unmatched-value cases; `RadioGroup.a11y.test.tsx` and `RadioGroup.a11y.chromium.spec.ts` (in `RadioList/__tests__`) `segmented-group-*` states; the radio-group pattern's aborted-press check on `segmented-option-unselected`; the `segmented-group-selected-rtl` state's arrow round trip under `dir="rtl"` | Arrows, wrap, Home, End; Tab-in with an unmatched or disabled selection | A value change on Tab entry, no wrap, or landing on a disabled segment fails. A press that slides off with focus outside the group and still selects fails. Evidence gap: no test covers a slide-off press while focus is already in the group. No test selects another segment after the stop has fallen back. | `audit:SegmentedControl/accessibility` |
-| FR4, ORD1 | `SegmentedControl.test.tsx` container handler forwarding cases | Caller `onKeyDown`, with and without `preventDefault` | A caller key handler that cannot cancel navigation fails. Evidence gap: no test asserts the caller `onFocus` order or the keyboard hint. | `audit:SegmentedControl/behavior` |
-| FR5 | `SegmentedControl.test.tsx` layout cases | Hug, fill, narrow row, icon-only | A control that overflows, or squeezes icon-only segments, fails. | `audit:SegmentedControl/layout` |
-| FR6 | Evidence gap: no test asserts size precedence or its propagation | — | — | `audit:SegmentedControl/layout` |
-| FR7, AR3 | `SegmentedControl.test.tsx` disabled and disabledMessage cases; `RadioGroup.a11y.test.tsx` and `RadioGroup.a11y.chromium.spec.ts` (in `RadioList/__tests__`) `segmented-group-disabled` and `segmented-group-disabled-with-message` states | Group and item disabled; with reason | A selection while disabled, or a missing reason tooltip, fails. Evidence gap: no test asserts the half opacity, or caller handlers while disabled. The `segmented-group-disabled` state declares `tabReachable: false`, asserting the current FR7 gap pending conformance. | `audit:SegmentedControl/accessibility` |
-| FR8 | `SegmentedControl.test.tsx` role-override and data-testid cases | Forwarded role | A forwarded prop that overrides the role fails. Evidence gap: no test asserts `ref` or a caller `aria-describedby`. | `audit:SegmentedControl/api` |
-| PR1 | Evidence gap: no test asserts the absence of global listeners | — | — | `audit:SegmentedControl/behavior` |
-| Target inventory | `packages/core/src/theme/themingTargets.test.ts` | Control and item targets | A rendered class absent from the documented targets fails. | `audit:SegmentedControl/theming` |
-| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and both current targets | Missing, extra, prefixed, or stale mappings fail repository validation. | `audit:SegmentedControl/theming` |
+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
+| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------- |
+| FR1, AR1 | `SegmentedControl.test.tsx` rendering, size, and data-testid cases; `RadioGroup.a11y.test.tsx` and `RadioGroup.a11y.chromium.spec.ts` (in `RadioList/__tests__`) `segmented-group-*` states | Control with several segments; sizes | Lost group semantics or name fails. Evidence gap: no test asserts the `segmented-control` target or `data-size`. | `audit:SegmentedControl/anatomy` |
+| FR2, FR3, ORD2, AR2 | `SegmentedControl.test.tsx` keyboard-navigation, unmatched-value and Tab-stop cases; `RadioGroup.a11y.test.tsx` and `RadioGroup.a11y.chromium.spec.ts` (in `RadioList/__tests__`) `segmented-group-*` states; the radio-group pattern's aborted-press check on `segmented-option-unselected`; the `segmented-group-selected-rtl` state's arrow round trip under `dir="rtl"` | Arrows, wrap, Home, End; Tab-in with an unmatched or disabled selection | A value change on Tab entry, no wrap, or landing on a disabled segment fails. A press that slides off with focus outside the group and still selects fails. Evidence gap: no test covers a slide-off press while focus is already in the group. | `audit:SegmentedControl/accessibility` |
+| FR4, ORD1 | `SegmentedControl.test.tsx` container handler forwarding cases | Caller `onKeyDown`, with and without `preventDefault` | A caller key handler that cannot cancel navigation fails. Evidence gap: no test asserts the caller `onFocus` order or the keyboard hint. | `audit:SegmentedControl/behavior` |
+| FR5 | `SegmentedControl.test.tsx` layout cases | Hug, fill, narrow row, icon-only | A control that overflows, or squeezes icon-only segments, fails. | `audit:SegmentedControl/layout` |
+| FR6 | Evidence gap: no test asserts size precedence or its propagation | — | — | `audit:SegmentedControl/layout` |
+| FR7, AR3 | `SegmentedControl.test.tsx` disabled and disabledMessage cases; `RadioGroup.a11y.test.tsx` and `RadioGroup.a11y.chromium.spec.ts` (in `RadioList/__tests__`) `segmented-group-disabled` and `segmented-group-disabled-with-message` states | Group and item disabled; with reason | A selection while disabled, or a missing reason tooltip, fails. Evidence gap: no test asserts the half opacity, or caller handlers while disabled. The `segmented-group-disabled` state declares a Tab stop. | `audit:SegmentedControl/accessibility` |
+| FR8 | `SegmentedControl.test.tsx` role-override and data-testid cases | Forwarded role | A forwarded prop that overrides the role fails. Evidence gap: no test asserts `ref` or a caller `aria-describedby`. | `audit:SegmentedControl/api` |
+| PR1 | Evidence gap: no test asserts the absence of global listeners | — | — | `audit:SegmentedControl/behavior` |
+| Target inventory | `packages/core/src/theme/themingTargets.test.ts` | Control and item targets | A rendered class absent from the documented targets fails. | `audit:SegmentedControl/theming` |
+| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and both current targets | Missing, extra, prefixed, or stale mappings fail repository validation. | `audit:SegmentedControl/theming` |
## Current-state impact
-- **Disabled Tab stop (FR7).** A control disabled without a reason has no Tab
- stop, against `spec:AST-085` FR1 and FR7.
-- **Disabled selected Tab stop (FR2).** Outside a group disabled with a
- reason, a disabled selected segment loses the Tab stop to the first enabled
- segment, against `spec:AST-085` FR1.
-- **Stale fallback Tab stop (FR2).** After the Tab stop falls back to the
- first enabled segment, selecting another segment by click or by `value`
- leaves the stop there, so Tab re-enters on an unchecked segment.
- **Press while focused (FR3).** A pointer press on another segment while focus
is in the group selects before any click, so a slide-off still selects,
against `spec:AST-020` FR9 and DEC-5.
diff --git a/docs/specs/components/SegmentedControl/SegmentedControlItem.spec.md b/docs/specs/components/SegmentedControl/SegmentedControlItem.spec.md
index 83d6b04f25..8e10893aa1 100644
--- a/docs/specs/components/SegmentedControl/SegmentedControlItem.spec.md
+++ b/docs/specs/components/SegmentedControl/SegmentedControlItem.spec.md
@@ -47,15 +47,15 @@ system_specs: [spec:AST-020, spec:AST-085, spec:AST-102]
## Contract at a glance
-| Area | Contract |
-| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| Public contract | None changes. SegmentedControlItem takes `value`, `label`, `isLabelHidden`, `icon`, `isDisabled`, and base props, and must sit inside a SegmentedControl. |
-| Behavior | One segment: a `<button role="radio">` with `aria-checked`. A click, or Space or Enter on the focused segment, selects it unless it is selected, disabled, or the caller's `onClick` prevents default. |
-| End-user impact | People see the selected segment raised and bold, and pick another with one click. Icon-only segments are still named. A disabled selected segment drops out of the tab order. |
-| Builder impact | None. |
-| Compatibility/readiness | Records shipped behavior; no API, default, or DOM change. A disabled selected segment leaves the tab order, a caller `onClick` runs while disabled or cannot veto a press while focused, a caller `className` is replaced, segments hold a fixed height, and a truncated `sm` segment can be under 24 px wide; all are listed under Current-state impact. |
-| Review checks | Reject a segment without a name, a click that selects a disabled segment, press paint on the selected or a disabled segment, or a lost forced-colors selected state. |
-| Governing rules | `component:SegmentedControl`; WAI-ARIA radio pattern; `spec:AST-020` FR9, FR15, DEC-5; `spec:AST-085` FR1, FR2; `spec:AST-102` FR4; `design:user-states` DR1–DR3 (pressed overlay, disabled non-response, and selected-segment exception); `architecture:public-component-api` INV5, INV6; WCAG 1.4.11. |
+| Area | Contract |
+| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| Public contract | None changes. SegmentedControlItem takes `value`, `label`, `isLabelHidden`, `icon`, `isDisabled`, and base props, and must sit inside a SegmentedControl. |
+| Behavior | One segment: a `<button role="radio">` with `aria-checked`. A click, or Space or Enter on the focused segment, selects it unless it is selected, disabled, or the caller's `onClick` prevents default. |
+| End-user impact | People see the selected segment raised and bold, and pick another with one click. Icon-only segments are still named. A disabled selected segment keeps the Tab stop. |
+| Builder impact | None. |
+| Compatibility/readiness | Records shipped behavior; no API, default, or DOM change. A caller `onClick` runs while disabled or cannot veto a press while focused, a caller `className` is replaced, segments hold a fixed height, and a truncated `sm` segment can be under 24 px wide; all are listed under Current-state impact. |
+| Review checks | Reject a segment without a name, a click that selects a disabled segment, press paint on the selected or a disabled segment, or a lost forced-colors selected state. |
+| Governing rules | `component:SegmentedControl`; WAI-ARIA radio pattern; `spec:AST-020` FR9, FR15, DEC-5; `spec:AST-085` FR1, FR2; `spec:AST-102` FR4; `design:user-states` DR1–DR3 (pressed overlay, disabled non-response, and selected-segment exception); `architecture:public-component-api` INV5, INV6; WCAG 1.4.11. |
This table is a review projection; the body below is authoritative.
@@ -108,7 +108,7 @@ Consumer migration instructions belong in consumer docs and release notes.
| FR1 | Each segment renders one `<button type="button" role="radio">` with `aria-checked` true when its `value` equals the group value, `data-value`, and the `segmented-control-item` target reflecting `data-size`, `data-selected`, and `data-disabled`. A forwarded prop cannot override the role. | WAI-ARIA radio pattern; current source and tests |
| FR2 | A click, including one from Space or Enter on the focused segment (native button activation; `spec:AST-020` FR15), runs the caller `onClick` first; unless it prevents default, an enabled, unselected segment passes its value to the group's `onChange`. Clicking the selected segment does nothing. The caller's `preventDefault()` MUST veto every press. Implementation gap: a press while focus is already in the group selects through `component:SegmentedControl` FR3 before the click, so the veto does not apply to it. | `spec:AST-020` FR15; current tests |
| FR3 | The segment renders its icon (sized to the segment size) followed by its label. With `isLabelHidden`, the label is not rendered and becomes `aria-label`, and the segment does not shrink. A visible label truncates with an ellipsis when the segment is narrower than it. | Current tests |
-| FR4 | A segment disabled by its own `isDisabled` or by the group sets `aria-disabled`, refuses selection, shows disabled text color, and shows no hover or press paint. A disabled selected segment MUST keep the Tab stop (`spec:AST-085` FR1); for a value that matches no segment, `component:SegmentedControl` FR2 places the stop. Implementation gap: a disabled selected segment leaves the tab order, except in a group disabled with a reason, and a caller `onClick` still runs on a disabled segment (`spec:AST-085` FR2). | `spec:AST-085` FR1, FR2; current tests |
+| FR4 | A segment disabled by its own `isDisabled` or by the group sets `aria-disabled`, refuses selection, shows disabled text color, and shows no hover or press paint. A disabled selected segment MUST keep the Tab stop (`spec:AST-085` FR1); for a value that matches no segment, `component:SegmentedControl` FR2 places the stop. Implementation gap: a caller `onClick` still runs on a disabled segment (`spec:AST-085` FR2). | `spec:AST-085` FR1, FR2; current tests |
| FR5 | The selected segment paints a raised surface with a low shadow and semibold primary text; under forced colors it paints `Highlight` with `HighlightText`. Unselected enabled segments paint the shared hover tint and, under `design:user-states` DR1 and DR2, the pressed overlay; the selected segment keeps its raised surface during a press (DR3). | WCAG 1.4.11; `design:user-states` DR1–DR3; current tests |
| FR6 | Segment height is the element height for the size minus 4 CSS px (24, 28, or 32) as a minimum that grows with a set text size under `spec:AST-102` FR4 (implementation gap: the height is fixed), with corners concentric with the control; `sm` uses supporting text and tighter padding. Keyboard focus paints the shared focus outline. | `architecture:interaction-modality` INV1; current source; `spec:AST-102` FR4 |
| FR7 | The segment owns `role`, `aria-checked`, `aria-disabled`, `aria-label` (set from the label when hidden), `tabIndex`, `type`, `data-value`, and `data-size`, and writes `data-selected`, `data-disabled`, and the press marker `data-astryx-pressable` in their own states; a caller value for an owned attribute is replaced, while a caller `data-selected`, `data-disabled`, or `data-astryx-pressable` passes through on segments outside that state. `ref`, other `data-*`, `style`, other ARIA such as `aria-describedby`, and other base props reach the button; `xstyle` composes last. Caller `className` MUST compose with the component's classes (`architecture:public-component-api` INV5, INV6). Implementation gap: the component's merged class replaces a caller `className`. | `architecture:public-component-api` INV5, INV6; current tests |
@@ -166,14 +166,14 @@ theming anatomy.
## Verification map
-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
-| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
-| FR1 | `SegmentedControl.test.tsx` aria-checked and data-testid cases; `RadioGroup.a11y.test.tsx` and `RadioGroup.a11y.chromium.spec.ts` (in `RadioList/__tests__`) `segmented-option-*` states | Selection change; data-testid | Stale `aria-checked` fails. Evidence gap: no test passes `role` to a segment; the role-override case covers the radiogroup. | `audit:SegmentedControlItem/accessibility` |
-| FR2 | `SegmentedControl.test.tsx` click and onClick-composition cases | Click; selected click; prevented click | A selected or prevented click that selects fails. Evidence gap: no test covers a press while focus is already in the group. | `audit:SegmentedControlItem/behavior` |
-| FR3 | `SegmentedControl.test.tsx` icon, icon-only, and truncation cases | Icon and label; icon-only; long label | A missing name, or an icon that truncates, fails. | `audit:SegmentedControlItem/anatomy` |
-| FR4 | `SegmentedControl.test.tsx` disabled cases; `RadioGroup.a11y.test.tsx` and `RadioGroup.a11y.chromium.spec.ts` (in `RadioList/__tests__`) `segmented-option-disabled` and `segmented-option-group-disabled*` states | Item and group disabled | A disabled segment that selects fails. Evidence gap: no test asserts the disabled text color, absent hover paint, or the caller `onClick` while disabled. The `segmented-option-group-disabled` state declares a checked, group-disabled segment with `tabReachable: false`, asserting the current FR4 gap pending conformance. | `audit:SegmentedControlItem/accessibility` |
-| FR5 | `SegmentedControl.test.tsx` forced-colors and pressed-state cases; `PressedState.a11y.chromium.spec.ts` segmented-control cases | Selected under forced colors; press; disabled | Lost forced-colors state, or press paint on a disabled segment, fails. Evidence gap: no test asserts the raised selected surface or the hover tint. | `audit:SegmentedControlItem/visual` |
-| FR6, FR7 | Evidence gap: no test of segment heights, text growth, focus outline, `ref`, or `xstyle` order | — | — | `audit:SegmentedControlItem/layout` |
+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
+| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
+| FR1 | `SegmentedControl.test.tsx` aria-checked and data-testid cases; `RadioGroup.a11y.test.tsx` and `RadioGroup.a11y.chromium.spec.ts` (in `RadioList/__tests__`) `segmented-option-*` states | Selection change; data-testid | Stale `aria-checked` fails. Evidence gap: no test passes `role` to a segment; the role-override case covers the radiogroup. | `audit:SegmentedControlItem/accessibility` |
+| FR2 | `SegmentedControl.test.tsx` click and onClick-composition cases | Click; selected click; prevented click | A selected or prevented click that selects fails. Evidence gap: no test covers a press while focus is already in the group. | `audit:SegmentedControlItem/behavior` |
+| FR3 | `SegmentedControl.test.tsx` icon, icon-only, and truncation cases | Icon and label; icon-only; long label | A missing name, or an icon that truncates, fails. | `audit:SegmentedControlItem/anatomy` |
+| FR4 | `SegmentedControl.test.tsx` disabled cases; `RadioGroup.a11y.test.tsx` and `RadioGroup.a11y.chromium.spec.ts` (in `RadioList/__tests__`) `segmented-option-disabled` and `segmented-option-group-disabled*` states | Item and group disabled | A disabled segment that selects fails. Evidence gap: no test asserts the disabled text color, absent hover paint, or the caller `onClick` while disabled. The `segmented-option-group-disabled` state declares a checked, group-disabled segment that keeps the Tab stop. | `audit:SegmentedControlItem/accessibility` |
+| FR5 | `SegmentedControl.test.tsx` forced-colors and pressed-state cases; `PressedState.a11y.chromium.spec.ts` segmented-control cases | Selected under forced colors; press; disabled | Lost forced-colors state, or press paint on a disabled segment, fails. Evidence gap: no test asserts the raised selected surface or the hover tint. | `audit:SegmentedControlItem/visual` |
+| FR6, FR7 | Evidence gap: no test of segment heights, text growth, focus outline, `ref`, or `xstyle` order | — | — | `audit:SegmentedControlItem/layout` |
## Current-state impact
@@ -188,9 +188,6 @@ theming anatomy.
caller's `onClick`, against `spec:AST-085` FR2.
- **Fixed height (FR6).** Segments hold a fixed height instead of growing with
a set text size, against `spec:AST-102` FR4.
-- **Disabled selected segment (FR4).** A disabled selected segment leaves the
- tab order, except in a group disabled with a reason when it is not itself
- `isDisabled`, against `spec:AST-085` FR1.
## Decision log
diff --git a/packages/core/src/RadioList/__tests__/RadioGroup.a11y.states.ts b/packages/core/src/RadioList/__tests__/RadioGroup.a11y.states.ts
index 208e126865..d20110d5cb 100644
--- a/packages/core/src/RadioList/__tests__/RadioGroup.a11y.states.ts
+++ b/packages/core/src/RadioList/__tests__/RadioGroup.a11y.states.ts
@@ -283,11 +283,10 @@ export const RADIO_GROUP_BINDING_STATES = [
{
id: 'segmented-group-disabled',
binding: 'SegmentedControl',
- summary: 'a disabled segmented group outside the tab sequence',
+ summary: 'a disabled segmented group with one tab stop',
facts: groupFacts({
disabled: true,
operable: false,
- tabReachable: false,
spaceSelection: false,
pointerSelection: false,
arrowSelection: false,
@@ -359,13 +358,12 @@ export const RADIO_GROUP_BINDING_STATES = [
{
id: 'segmented-option-group-disabled',
binding: 'SegmentedControlItem',
- summary:
- 'a selected segment disabled by its group and removed from Tab order',
+ summary: 'a selected segment disabled by its group that keeps the Tab stop',
facts: optionFacts({
checked: true,
disabled: true,
operable: false,
- tabReachable: false,
+ tabReachable: true,
pointerCancellation: false,
}),
subjectName: 'List',
diff --git a/packages/core/src/SegmentedControl/SegmentedControl.doc.mjs b/packages/core/src/SegmentedControl/SegmentedControl.doc.mjs
index 7eb8bba4dd..45a2a8adc3 100644
--- a/packages/core/src/SegmentedControl/SegmentedControl.doc.mjs
+++ b/packages/core/src/SegmentedControl/SegmentedControl.doc.mjs
@@ -132,14 +132,14 @@ function WorkspaceCard() {
{
name: 'isDisabled',
type: 'boolean',
- description: 'Whether the entire control is disabled.',
+ description: 'Whether the entire control is disabled. The selected segment keeps the Tab stop, announced as disabled (aria-disabled), and nothing can be selected.',
default: 'false',
},
{
name: 'disabledMessage',
type: 'string',
description:
- 'Explains why the control is disabled. Applies to the whole-group disabled state (isDisabled), not per segment. With isDisabled, shows a tooltip on hover/keyboard focus and keeps the control focusable via aria-disabled (selection stays blocked). Use this instead of wrapping a disabled SegmentedControl in Tooltip. Disabled controls swallow the hover events an external Tooltip needs.',
+ 'Explains why the control is disabled. Applies to the whole-group disabled state (isDisabled), not per segment. With isDisabled, shows a tooltip on hover/keyboard focus, and the reason describes each segment (selection stays blocked). Use this instead of wrapping a disabled SegmentedControl in Tooltip, so the reason is attached to the control itself.',
},
{
name: 'children',
@@ -230,7 +230,7 @@ function WorkspaceCard() {
{guidance: true, description: 'Provide a descriptive label for the control to ensure the group is accessible to screen readers.'},
{guidance: false, description: 'Use for page-level navigation; use TabList instead. TabList is a navigation component, while SegmentedControl is an input that always has exactly one selected option.'},
{guidance: false, description: 'Use for simple on/off states; use ToggleButton instead. ToggleButton can be toggled on or off independently, while SegmentedControl enforces a single selection from a group.'},
- {guidance: false, description: 'Wrap a disabled SegmentedControl in Tooltip to explain why it is disabled; disabled controls swallow the hover events the wrapper needs. Use the disabledMessage prop instead.'},
+ {guidance: false, description: 'Wrap a disabled SegmentedControl in Tooltip to explain why it is disabled; the reason is then not attached to the control or its segments. Use the disabledMessage prop instead.'},
],
},
};
@@ -246,7 +246,7 @@ export const docsZh = {
{guidance: true, description: 'Provide a descriptive label for the control to ensure the group is accessible to screen readers.'},
{guidance: false, description: 'Use for page-level navigation; use TabList instead. TabList is a navigation component, while SegmentedControl is an input that always has exactly one selected option.'},
{guidance: false, description: 'Use for simple on/off states; use ToggleButton instead. ToggleButton can be toggled on or off independently, while SegmentedControl enforces a single selection from a group.'},
- {guidance: false, description: 'Wrap a disabled SegmentedControl in Tooltip to explain why it is disabled; disabled controls swallow the hover events the wrapper needs. Use the disabledMessage prop instead.'},
+ {guidance: false, description: 'Wrap a disabled SegmentedControl in Tooltip to explain why it is disabled; the reason is then not attached to the control or its segments. Use the disabledMessage prop instead.'},
],
},
};
@@ -262,7 +262,7 @@ export const docsDense = {
{guidance: true, description: 'Provide a descriptive label for the control to ensure the group is accessible to screen readers.'},
{guidance: false, description: 'Use for page-level navigation; use TabList instead. TabList is a navigation component, while SegmentedControl is an input that always has exactly one selected option.'},
{guidance: false, description: 'Use for simple on/off states; use ToggleButton instead. ToggleButton can be toggled on or off independently, while SegmentedControl enforces a single selection from a group.'},
- {guidance: false, description: 'Wrap a disabled SegmentedControl in Tooltip to explain why it is disabled; disabled controls swallow the hover events the wrapper needs. Use the disabledMessage prop instead.'},
+ {guidance: false, description: 'Wrap a disabled SegmentedControl in Tooltip to explain why it is disabled; the reason is then not attached to the control or its segments. Use the disabledMessage prop instead.'},
],
},
propDescriptions: {
diff --git a/packages/core/src/SegmentedControl/SegmentedControl.test.tsx b/packages/core/src/SegmentedControl/SegmentedControl.test.tsx
index 6f338d0a6b..0e234adf36 100644
--- a/packages/core/src/SegmentedControl/SegmentedControl.test.tsx
+++ b/packages/core/src/SegmentedControl/SegmentedControl.test.tsx
@@ -366,6 +366,104 @@ describe('SegmentedControl', () => {
});
});
+describe('SegmentedControl Tab stop (spec:AST-085 FR1)', () => {
+ function tabStops() {
+ return screen
+ .getAllByRole('radio')
+ .filter(radio => radio.tabIndex === 0)
+ .map(radio => radio.textContent);
+ }
+
+ it('keeps one Tab stop on the selected segment of a control disabled without a reason', async () => {
+ const user = userEvent.setup();
+ const onChange = vi.fn();
+ render(
+ <>
+ <button type="button">Before</button>
+ <SegmentedControl
+ label="View"
+ value="list"
+ onChange={onChange}
+ isDisabled>
+ <SegmentedControlItem value="grid" label="Grid" />
+ <SegmentedControlItem value="list" label="List" />
+ </SegmentedControl>
+ </>,
+ );
+ expect(tabStops()).toEqual(['List']);
+ screen.getByRole('button', {name: 'Before'}).focus();
+ await user.tab();
+ const list = screen.getByRole('radio', {name: 'List'});
+ expect(list).toHaveFocus();
+ expect(list).toHaveAttribute('aria-disabled', 'true');
+ await user.keyboard('{ArrowLeft}');
+ await user.click(screen.getByRole('radio', {name: 'Grid'}));
+ expect(onChange).not.toHaveBeenCalled();
+ });
+
+ it('keeps the Tab stop on a selected segment that is disabled in an enabled control', async () => {
+ const user = userEvent.setup();
+ const onChange = vi.fn();
+ render(
+ <>
+ <button type="button">Before</button>
+ <SegmentedControl label="View" value="list" onChange={onChange}>
+ <SegmentedControlItem value="grid" label="Grid" />
+ <SegmentedControlItem value="list" label="List" isDisabled />
+ <SegmentedControlItem value="table" label="Table" />
+ </SegmentedControl>
+ </>,
+ );
+ expect(tabStops()).toEqual(['List']);
+ screen.getByRole('button', {name: 'Before'}).focus();
+ await user.tab();
+ expect(screen.getByRole('radio', {name: 'List'})).toHaveFocus();
+ expect(onChange).not.toHaveBeenCalled();
+ // Arrows move from it to the enabled segment beside it and select it.
+ await user.keyboard('{ArrowRight}');
+ expect(onChange).toHaveBeenCalledWith('table');
+ expect(screen.getByRole('radio', {name: 'Table'})).toHaveFocus();
+ expect(tabStops()).toHaveLength(1);
+ });
+
+ it('moves left from a disabled selected segment to the enabled segment beside it', async () => {
+ const user = userEvent.setup();
+ const onChange = vi.fn();
+ render(
+ <SegmentedControl label="View" value="list" onChange={onChange}>
+ <SegmentedControlItem value="grid" label="Grid" />
+ <SegmentedControlItem value="list" label="List" isDisabled />
+ <SegmentedControlItem value="table" label="Table" />
+ </SegmentedControl>,
+ );
+ screen.getByRole('radio', {name: 'List'}).focus();
+ await user.keyboard('{ArrowLeft}');
+ expect(onChange).toHaveBeenCalledWith('grid');
+ expect(screen.getByRole('radio', {name: 'Grid'})).toHaveFocus();
+ });
+
+ it('moves a fallen-back Tab stop to the segment selected later', () => {
+ const props = {label: 'View', onChange: () => {}};
+ const items = [
+ <SegmentedControlItem key="grid" value="grid" label="Grid" />,
+ <SegmentedControlItem key="list" value="list" label="List" />,
+ <SegmentedControlItem key="table" value="table" label="Table" />,
+ ];
+ const {rerender} = render(
+ <SegmentedControl {...props} value="archived">
+ {items}
+ </SegmentedControl>,
+ );
+ expect(tabStops()).toEqual(['Grid']);
+ rerender(
+ <SegmentedControl {...props} value="table">
+ {items}
+ </SegmentedControl>,
+ );
+ expect(tabStops()).toEqual(['Table']);
+ });
+});
+
describe('SegmentedControl keyboard navigation', () => {
describe('tab-through is a pure focus move (#3597)', () => {
it('does not fire onChange when tabbing in with an unmatched value', async () => {
diff --git a/packages/core/src/SegmentedControl/SegmentedControl.tsx b/packages/core/src/SegmentedControl/SegmentedControl.tsx
index c19ad97475..51a429daab 100644
--- a/packages/core/src/SegmentedControl/SegmentedControl.tsx
+++ b/packages/core/src/SegmentedControl/SegmentedControl.tsx
@@ -65,7 +65,9 @@ export interface SegmentedControlProps extends Omit<
*/
layout?: SegmentedControlLayout;
/**
- * Whether the entire control is disabled.
+ * Whether the entire control is disabled. The selected segment keeps the
+ * control's Tab stop, announced as disabled (`aria-disabled`), and nothing
+ * can be selected.
* @default false
*/
isDisabled?: boolean;
@@ -73,11 +75,11 @@ export interface SegmentedControlProps extends Omit<
* Explains why the control is disabled. Applies to the whole-group disabled
* state (`isDisabled`), not individual segments. When set together with
* `isDisabled`, the control shows a tooltip with this text on hover and
- * keyboard focus, and stays focusable (via `aria-disabled`) so the reason is
- * discoverable by keyboard and assistive technology. Selection stays blocked.
+ * keyboard focus, and the reason describes each segment for assistive
+ * technology. Selection stays blocked.
*
- * Use this instead of wrapping a disabled control in `Tooltip` — disabled
- * controls don't emit the pointer events an external tooltip needs.
+ * Use this instead of wrapping a disabled control in `Tooltip`, so the
+ * reason is attached to the control itself.
*/
disabledMessage?: string;
/**
@@ -119,15 +121,11 @@ const styles = stylex.create({
display: 'flex',
width: '100%',
},
+ // Disabled: dimmed, with pointer events left on so a press can focus the
+ // segment that holds the Tab stop and a reason tooltip can open on hover.
+ // Selection is blocked by the isDisabled guards (spec:AST-085 FR1, FR2).
disabled: {
opacity: 0.5,
- pointerEvents: 'none',
- },
- // Disabled *with* a disabledMessage: keep the dimmed look but leave pointer
- // events on so the group can receive hover and surface the reason tooltip.
- // Selection is still blocked by the isDisabled guards.
- disabledWithMessage: {
- opacity: 0.5,
},
});
@@ -180,11 +178,10 @@ export function SegmentedControl({
}: SegmentedControlProps) {
const size = useSize(sizeProp, 'md');
- // Disabled-reason tooltip. Applies to the whole-group disabled state. Disabled
- // controls swallow pointer events, so the tooltip listeners attach to the
- // radiogroup container (and the container keeps pointer events on in this
- // mode) while the radios stay perceivable via aria-disabled. Selection is
- // blocked by the isDisabled guards in the click/focus handlers.
+ // Disabled-reason tooltip. Applies to the whole-group disabled state. The
+ // tooltip listeners attach to the radiogroup container, which keeps pointer
+ // events while disabled; the radios stay perceivable via aria-disabled.
+ // Selection is blocked by the isDisabled guards in the click/focus handlers.
const showsDisabledMessage = isDisabled && !!disabledMessage;
const disabledMessageTooltip = useTooltip({
placement: 'above',
@@ -203,10 +200,10 @@ export function SegmentedControl({
useInternalListFocus<HTMLDivElement>({
itemSelector: '[role="radio"]:not([aria-disabled="true"])',
hasRovingTabIndex: true,
- // Disabled with a reason, the control keeps one Tab stop so the reason is
- // reachable (FR2, FR7): the selected segment, else the first segment not
- // disabled by its own isDisabled, else the first.
- disabledTabStop: showsDisabledMessage ? orderDisabledTabStop : undefined,
+ // One Tab stop, placed by the control (FR2, FR7): the selected segment,
+ // enabled or not and in a disabled control too, else the first segment
+ // not disabled by its own isDisabled, else the first.
+ tabStopOrder: orderTabStop,
wrap: true,
orientation: 'horizontal',
});
@@ -276,7 +273,6 @@ export function SegmentedControl({
size,
layout,
isDisabled,
- hasDisabledMessage: showsDisabledMessage,
disabledReasonID: showsDisabledMessage
? disabledMessageTooltip.describedBy
: undefined,
@@ -314,10 +310,7 @@ export function SegmentedControl({
styles.container,
sizeStyles[size],
layout === 'fill' && styles.fill,
- isDisabled &&
- (showsDisabledMessage
- ? styles.disabledWithMessage
- : styles.disabled),
+ isDisabled && styles.disabled,
xstyle,
),
className,
@@ -335,11 +328,11 @@ export function SegmentedControl({
SegmentedControl.displayName = 'SegmentedControl';
/**
- * The segments of a control disabled with a reason, its Tab stop first: the
- * selected segment, else the first segment not disabled by its own
- * isDisabled, else the first (FR2, FR7).
+ * The control's segments, its Tab stop first: the selected segment, enabled
+ * or not, else the first segment not disabled by its own isDisabled, else the
+ * first (FR2, FR7).
*/
-function orderDisabledTabStop(list: HTMLElement): ReadonlyArray<HTMLElement> {
+function orderTabStop(list: HTMLElement): ReadonlyArray<HTMLElement> {
const segments = Array.from(
list.querySelectorAll<HTMLElement>('[role="radio"]'),
);
diff --git a/packages/core/src/SegmentedControl/SegmentedControlContext.ts b/packages/core/src/SegmentedControl/SegmentedControlContext.ts
index 66a845d015..6ec5126d89 100644
--- a/packages/core/src/SegmentedControl/SegmentedControlContext.ts
+++ b/packages/core/src/SegmentedControl/SegmentedControlContext.ts
@@ -24,15 +24,8 @@ export interface SegmentedControlContextValue {
layout: SegmentedControlLayout;
isDisabled: boolean;
/**
- * True when the whole control is disabled *and* a `disabledMessage` is set.
- * In that mode the selected segment stays focusable (via `aria-disabled`
- * rather than being dropped from the tab order) so the group's disabled-reason
- * tooltip is keyboard-discoverable; selection is still blocked.
- */
- hasDisabledMessage?: boolean;
- /**
- * The id of the group's disabled-reason tooltip while `hasDisabledMessage`
- * is true. It also describes each segment, so the segment that has focus is
+ * The id of the group's disabled-reason tooltip while the group is disabled
+ * with a `disabledMessage`. It also describes each segment, so the segment that has focus is
* described by the reason (spec:AST-085 FR5).
*/
disabledReasonID?: string;
diff --git a/packages/core/src/SegmentedControl/SegmentedControlItem.doc.mjs b/packages/core/src/SegmentedControl/SegmentedControlItem.doc.mjs
index b245027919..af5da7183a 100644
--- a/packages/core/src/SegmentedControl/SegmentedControlItem.doc.mjs
+++ b/packages/core/src/SegmentedControl/SegmentedControlItem.doc.mjs
@@ -52,7 +52,7 @@ export const docs = {
{
name: 'isDisabled',
type: 'boolean',
- description: 'Whether this individual item is disabled.',
+ description: "Whether this individual item is disabled. A disabled selected item keeps the control's Tab stop.",
default: 'false',
},
],
diff --git a/packages/core/src/SegmentedControl/SegmentedControlItem.tsx b/packages/core/src/SegmentedControl/SegmentedControlItem.tsx
index cb190f3bb1..fe02152e51 100644
--- a/packages/core/src/SegmentedControl/SegmentedControlItem.tsx
+++ b/packages/core/src/SegmentedControl/SegmentedControlItem.tsx
@@ -202,15 +202,6 @@ export function SegmentedControlItem({
const isSelected = ctx.value === value;
const isItemDisabled = isDisabled || ctx.isDisabled;
- // When the whole group is disabled with a disabledMessage, keep the selected
- // segment focusable so the group's reason tooltip is keyboard-discoverable.
- // Per-item disabling (`isDisabled` on the item) always drops out of the tab
- // order. Activation stays blocked by the isItemDisabled guard in handleClick.
- // Disabled with a reason, the selected segment keeps the Tab stop even when
- // it is itself disabled (FR4); with no selected segment, the group places
- // the stop (SegmentedControl FR2).
- const keepsSelectedFocusable =
- isSelected && (ctx.hasDisabledMessage ?? false);
const size: SegmentedControlSize = ctx.size;
const isFill = ctx.layout === 'fill';
@@ -248,14 +239,10 @@ export function SegmentedControlItem({
// The group's fallback Tab stop skips segments disabled on their own.
{...segmentDisabledProps(isDisabled)}
{...(!isSelected && !isItemDisabled ? pressable : undefined)}
- // Disabled items (including when the whole group is disabled) are not tab
- // stops — otherwise the selected segment stays keyboard-focusable but is
- // silently dead (arrows and activation are no-ops) (navigation-13). The
- // exception is a whole-group disabledMessage, where the selected segment
- // stays focusable so the reason tooltip is keyboard-discoverable.
- tabIndex={
- (isSelected && !isItemDisabled) || keepsSelectedFocusable ? 0 : -1
- }
+ // The selected segment holds the Tab stop, disabled or not (spec:AST-085
+ // FR1); activation stays blocked by the isItemDisabled guard. With no
+ // selected segment, the group places the stop (SegmentedControl FR2).
+ tabIndex={isSelected ? 0 : -1}
onClick={handleClick}
{...mergeProps(
themeProps('segmented-control-item', {
diff --git a/packages/core/src/hooks/useListFocus.test.tsx b/packages/core/src/hooks/useListFocus.test.tsx
index 493846d3a5..6d43b3e9eb 100644
--- a/packages/core/src/hooks/useListFocus.test.tsx
+++ b/packages/core/src/hooks/useListFocus.test.tsx
@@ -185,7 +185,7 @@ describe('useListFocus roving tabindex (hasRovingTabIndex)', () => {
const {rerender} = render(
<RovingToolbar
disabledLabels={ROVING_LABELS}
- disabledTabStop={orderBy('B')}
+ tabStopOrder={orderBy('B')}
/>,
);
expect(screen.getByTestId('B')).toHaveAttribute('tabindex', '0');
@@ -196,7 +196,7 @@ describe('useListFocus roving tabindex (hasRovingTabIndex)', () => {
rerender(
<RovingToolbar
disabledLabels={ROVING_LABELS}
- disabledTabStop={orderBy('A')}
+ tabStopOrder={orderBy('A')}
/>,
);
expect(screen.getByTestId('A')).toHaveAttribute('tabindex', '0');
@@ -204,6 +204,15 @@ describe('useListFocus roving tabindex (hasRovingTabIndex)', () => {
expect(screen.getByTestId('C')).toHaveAttribute('tabindex', '-1');
});
+ it('puts the stop where the callback says while items are enabled too, even on a disabled item', () => {
+ render(
+ <RovingToolbar disabledLabels={['B']} tabStopOrder={orderBy('B')} />,
+ );
+ expect(screen.getByTestId('B')).toHaveAttribute('tabindex', '0');
+ expect(screen.getByTestId('A')).toHaveAttribute('tabindex', '-1');
+ expect(screen.getByTestId('C')).toHaveAttribute('tabindex', '-1');
+ });
+
it('ArrowRight moves the tab stop to the next enabled item', () => {
render(<RovingToolbar />);
const toolbar = screen.getByRole('toolbar');
diff --git a/packages/core/src/hooks/useListFocus.ts b/packages/core/src/hooks/useListFocus.ts
index e72d49f9b0..880e37261c 100644
--- a/packages/core/src/hooks/useListFocus.ts
+++ b/packages/core/src/hooks/useListFocus.ts
@@ -128,13 +128,16 @@ export interface UseListFocusOptions {
*/
export interface InternalListFocusOptions extends UseListFocusOptions {
/**
- * With `hasRovingTabIndex`, keeps one tab stop while every item is disabled:
- * returns the elements that share it, the stop first. The hook gives the
- * first `tabindex="0"` and the rest `tabindex="-1"`. For a group that stays
- * focusable while disabled, so its disabled reason is reachable by keyboard.
- * Unset (the default): no item holds the stop while every item is disabled.
+ * With `hasRovingTabIndex`, the owner places the one tab stop: returns the
+ * elements that share it, the stop first, enabled or not. After every
+ * commit and every keyboard move the hook gives the first `tabindex="0"`
+ * and the rest `tabindex="-1"`. For a group whose stop follows its own
+ * state, such as a radio group whose checked item keeps the stop even when
+ * that item, or the whole group, is disabled.
+ * Unset (the default): the first enabled item holds the stop, kept across
+ * renders, and no item holds it while every item is disabled.
*/
- disabledTabStop?: (list: HTMLElement) => ReadonlyArray<HTMLElement>;
+ tabStopOrder?: (list: HTMLElement) => ReadonlyArray<HTMLElement>;
/**
* Moves focus with the focus the last input calls for
* (`architecture:interaction-modality` INV1): after a pointer press a
@@ -369,7 +372,7 @@ export function useInternalListFocus<T extends HTMLElement = HTMLElement>(
hasHomeEnd = true,
hasPaging = false,
hasRovingTabIndex = false,
- disabledTabStop,
+ tabStopOrder,
hasCaretGuard = false,
focusFollowsLastInput = false,
} = options;
@@ -495,14 +498,9 @@ export function useInternalListFocus<T extends HTMLElement = HTMLElement>(
* enabled; otherwise promote the first enabled item (tab-stop repair).
*/
const syncTabStops = useCallback(() => {
- const items = getItems();
- const enabled = items.filter(el => !isItemDisabled(el));
- if (enabled.length === 0) {
- const listEl = listRef.current;
- if (listEl == null || disabledTabStop == null) {
- return;
- }
- const [stop, ...others] = disabledTabStop(listEl);
+ const listEl = listRef.current;
+ if (listEl != null && tabStopOrder != null) {
+ const [stop, ...others] = tabStopOrder(listEl);
if (stop != null) {
setTabIndex(stop, 0);
}
@@ -511,12 +509,17 @@ export function useInternalListFocus<T extends HTMLElement = HTMLElement>(
}
return;
}
+ const items = getItems();
+ const enabled = items.filter(el => !isItemDisabled(el));
+ if (enabled.length === 0) {
+ return;
+ }
const current = enabled.find(el => el.getAttribute('tabindex') === '0');
const tabbable = current ?? enabled[0];
for (const el of items) {
setTabIndex(el, el === tabbable ? 0 : -1);
}
- }, [getItems, isItemDisabled, setTabIndex, disabledTabStop]);
+ }, [getItems, isItemDisabled, setTabIndex, tabStopOrder]);
// Keep the tab stop valid across renders (items added/removed, disabled
// toggled). Runs after every commit but only when roving tabindex is on.
@@ -537,7 +540,14 @@ export function useInternalListFocus<T extends HTMLElement = HTMLElement>(
return;
}
if (hasRovingTabIndex) {
- for (const el of items) {
+ // An owner-placed stop may sit on an element outside `items`, such as
+ // a disabled checked radio; it gives way to the target too.
+ const listEl = listRef.current;
+ const sharing =
+ listEl != null && tabStopOrder != null
+ ? [...items, ...tabStopOrder(listEl)]
+ : items;
+ for (const el of sharing) {
setTabIndex(el, el === target ? 0 : -1);
}
}
@@ -547,7 +557,7 @@ export function useInternalListFocus<T extends HTMLElement = HTMLElement>(
target.focus();
}
},
- [hasRovingTabIndex, setTabIndex, focusFollowsLastInput],
+ [hasRovingTabIndex, setTabIndex, focusFollowsLastInput, tabStopOrder],
);
/**
@@ -757,16 +767,34 @@ export function useInternalListFocus<T extends HTMLElement = HTMLElement>(
const currentIndex = getCurrentIndex();
const items = getItems();
+ let nextFrom = currentIndex === -1 ? 0 : currentIndex + 1;
+ let prevFrom = currentIndex === -1 ? items.length - 1 : currentIndex - 1;
+ // Focus on an owner-placed stop outside `items`, such as a disabled
+ // checked radio, moves to the enabled item beside it in document order.
+ const active = document.activeElement;
+ if (
+ currentIndex === -1 &&
+ tabStopOrder != null &&
+ active != null &&
+ listRef.current?.contains(active)
+ ) {
+ const after = items.findIndex(
+ item =>
+ (active.compareDocumentPosition(item) &
+ Node.DOCUMENT_POSITION_FOLLOWING) !==
+ 0,
+ );
+ nextFrom = after === -1 ? items.length : after;
+ prevFrom = nextFrom - 1;
+ }
if (isNext) {
- const from = currentIndex === -1 ? 0 : currentIndex + 1;
- const next = findEnabledIndex(items, from, 1, wrap);
+ const next = findEnabledIndex(items, nextFrom, 1, wrap);
if (next !== -1) {
focusIndex(items, next);
}
} else if (isPrev) {
- const from = currentIndex === -1 ? items.length - 1 : currentIndex - 1;
- const prev = findEnabledIndex(items, from, -1, wrap);
+ const prev = findEnabledIndex(items, prevFrom, -1, wrap);
if (prev !== -1) {
focusIndex(items, prev);
}
@@ -797,6 +825,7 @@ export function useInternalListFocus<T extends HTMLElement = HTMLElement>(
focusPage,
onEscape,
ownsEvent,
+ tabStopOrder,
],
);