Skip to content

feat(react-switch): add disabledFocusable prop#35799

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/add-disabled-focusable-to-switch
Draft

feat(react-switch): add disabledFocusable prop#35799
Copilot wants to merge 2 commits intomasterfrom
copilot/add-disabled-focusable-to-switch

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

Switch lacked a disabledFocusable prop, forcing consumers to manually simulate visually-disabled-but-focusable behavior—leading to inconsistent, error-prone implementations. This adds disabledFocusable to Switch, consistent with Button and other Fluent UI interactive components.

Changes

  • Switch.types.ts — Added disabledFocusable?: boolean to SwitchProps; added to SwitchState required picks
  • useSwitch.tsx — When disabledFocusable=true:
    • Sets aria-disabled="true" on the <input> instead of disabled (keeps element in tab order)
    • Calls ev.preventDefault() in the change handler to block state mutation
    • Passes disabled || disabledFocusable to Label for consistent visual state
    • Excludes disabledFocusable from native props forwarded to <input>
  • useSwitchStyles.styles.ts — Added [aria-disabled="true"] CSS selectors in useInputBaseClassName mirroring the :disabled rules. Key specificity considerations:
    • [aria-disabled="true"]:not(:checked) and [aria-disabled="true"]:checked variants match the specificity (0,4,0) of the :enabled:not(:checked) / :enabled:checked rules and are ordered after them in the reset class to win the cascade
    • Forced-colors variants (ButtonFace/GrayText) placed after :enabled:checked to override the Highlight active styles
  • Switch.test.tsx — Added tests for focus retention, checked-state immutability, and onChange suppression when disabledFocusable
  • SwitchDisabled.stories.tsx — Added unchecked and checked disabledFocusable examples

Usage

// Switch remains in the tab order and appears disabled, but focus is not lost
<Switch disabledFocusable label="Feature unavailable" />
<Switch checked disabledFocusable label="Active but locked" />

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: mainframev <14054752+mainframev@users.noreply.github.com>
Copilot AI changed the title [WIP] Add disabledFocusable to Switch component feat(react-switch): add disabledFocusable prop Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants