base-ui icon indicating copy to clipboard operation
base-ui copied to clipboard

[radio group] A disabled checked radio becomes the only tab stop, so Tab skips the group

Open TannazJamshidi opened this issue 1 month ago • 3 comments

Bug report

Current behavior

In a RadioGroup whose checked Radio is disabled, the disabled radio becomes the group's only tab stop (tabindex="0"), and every other radio gets tabindex="-1". With nativeButton, the disabled radio is a <button disabled>, which cannot take focus, so Tab skips the whole group: the enabled radios cannot be reached from the keyboard. Without nativeButton, Tab lands on an item that cannot be selected.

Expected behavior

A disabled radio is never the tab stop. When the checked radio is disabled, the tab stop goes to the first enabled radio, as it already does when nothing is checked.

Reproducible example

import { Radio } from "@base-ui/react/radio";
import { RadioGroup } from "@base-ui/react/radio-group";

export default function App() {
  return (
    <RadioGroup aria-label="View" defaultValue="day">
      <Radio.Root value="day" disabled nativeButton render={<button type="button" />}>
        Day
      </Radio.Root>
      <Radio.Root value="week" nativeButton render={<button type="button" />}>
        Week
      </Radio.Root>
      <Radio.Root value="month" nativeButton render={<button type="button" />}>
        Month
      </Radio.Root>
    </RadioGroup>
  );
}

Tab stops after mount: Day 0 (disabled), Week -1, Month -1. Pressing Tab from before the group skips it entirely.

Cause

RadioRoot marks the checked radio with data-composite-item-active (radio/root/RadioRoot.mjs:114). On mount, useCompositeRoot makes the marked item the highlighted index and returns, without checking whether it is disabled (internals/composite/root/useCompositeRoot.mjs:69-75). The fallback to the first enabled item just below only runs when no item is marked.

Removing the marker from a disabled radio (passing data-composite-item-active={undefined}) gives Day -1, Week 0, Month -1, which suggests the fix is to skip a disabled active item there, or to not mark a disabled radio as active.

Your environment

  • @base-ui/react 1.9.0
  • React 19

Radix's RadioGroup / ToggleGroup forwarded focus to the first enabled item in this case.

TannazJamshidi avatar Nov 05 '26 17:11 TannazJamshidi

Thanks for the clear write-up. I’ve got a small fix that skips a disabled checked radio and falls back to the first enabled one. I’d like to pick this up, if that’s OK.

helloigig avatar Nov 06 '26 10:11 helloigig

ROI review · after implementation

PR assessed: #6193.

🟢 Fix — recommended. Review PR #6193; merge only after its required checks pass.

medium confidence — The bug blocks keyboard access to the group. The PR fixes it in Chrome. The one-line option breaks a checked radio that becomes enabled, so the extra effect is justified.

Existing-API assessment: Avoid checking a disabled radio in app code. Not tested.

Consideration Assessment
Design foundation suitable: RadioRoot owns both checked and disabled state, and the PR reuses a proven Tabs pattern. Real browser runs confirm the fix and show the smaller option falls short.
Benefit / reach Keyboard users skip the group or land on a radio they cannot pick. No duplicates found; reach unknown. Any group whose value names a disabled radio.
Severity / workaround Accessibility barrier for keyboard users. Avoid checking a disabled radio in app code. Not tested.
Cost / risk Measured diff: 73 changed lines; 0 added dependencies; bundle delta: 279 bytes. Radio entry gains 279 gzip bytes. No new dependencies. One layout effect per radio. 73 source lines. A local wrapper replaces CompositeItem and repeats the Tabs sync effect. Reverses an older disabled tab stop test. Outside value changes now move the tab stop; not tested.
Alternatives / next step The one-line marker change failed the becomes-enabled case. Sharing the effect with Tabs could cut duplication. Add tests for an outside value change and for a checked radio disabled after mount.

Affected too? Add a 👍 reaction and tell us how this affects your app. Feedback is welcome. This review can change.


🤖 Comment posted by Claude

jjenzz avatar Nov 06 '26 12:11 jjenzz

Thanks, that’s much cleaner. I moved the fix into RadioRoot so a radio only marks itself active when it’s checked and enabled, reverted the composite change, and kept the real Tab key test.

helloigig avatar Nov 06 '26 17:11 helloigig