Skip to content

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

Open
Copilot wants to merge 6 commits intomasterfrom
copilot/add-disabled-focusable-to-switch
Open

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

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

  • Explore Switch component and understand disabledFocusable patterns from Button/Checkbox
  • Add disabledFocusable prop to Switch.types.ts (in SwitchProps and SwitchState)
  • Update useSwitch.tsx to handle disabledFocusable:
    • Set aria-disabled="true" instead of disabled attribute
    • onChange is unconditional (always calls user callback)
    • onClick calls ev.preventDefault() to block state toggle when disabledFocusable
    • onKeyDown blocks Space/Enter when disabledFocusable
    • Pass disabled appearance to Label
  • Update useSwitchStyles.styles.ts to combine selectors instead of duplicating
  • Add tests for disabledFocusable in Switch.test.tsx
  • Add disabledFocusable story to SwitchDisabled.stories.tsx
  • Update react-switch.api.md with new API
  • Add beachball change file
  • Run yarn nx format (scoped to react-switch package only)
Screen.Recording.2026-02-27.at.20.14.16.mov

✨ 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
},

// DisabledFocusable (both checked and unchecked) - must come after :enabled: blocks to override them
'[aria-disabled="true"]': {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

instead of duplicating existing styles for aria-disabled adjust current disable selectors:

-  ':disabled': {   
+  ':disabled, &[aria-disabled="true"]': {
-  ':enabled:not(:checked)': {
+  ':enabled:not(:checked):not([aria-disabled="true"])': {
- ':enabled:checked': { 
+ ':enabled:checked:not([aria-disabled="true"])': {
- ':disabled:not(:checked)': { 
+ ':disabled:not(:checked), &[aria-disabled="true"]:not(:checked)': {
- ':disabled:not(:checked)': { 
+ ':disabled:not(:checked), &[aria-disabled="true"]:not(:checked)': { 
- ':disabled:checked': {  
+ ':disabled:checked, &[aria-disabled="true"]:checked': {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 48c9dbc. Refactored to combine selectors as suggested — :disabled, &[aria-disabled="true"], :enabled:not(:checked):not([aria-disabled="true"]), :enabled:checked:not([aria-disabled="true"]), and the checked/unchecked variants — removing all the duplicated [aria-disabled] blocks.

Comment on lines 54 to 62
/**
* Whether the switch should be disabled and focusable. This is used in scenarios where it is important to keep a
* consistent tab order for screen reader and keyboard users. The primary example of this pattern is when the
* disabled switch is in a list or a form and is seldom used for standalone switches.
*
* @default false
*/
disabledFocusable?: boolean;

Copy link
Contributor

@mainframev mainframev Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

Suggested change
/**
* Whether the switch should be disabled and focusable. This is used in scenarios where it is important to keep a
* consistent tab order for screen reader and keyboard users. The primary example of this pattern is when the
* disabled switch is in a list or a form and is seldom used for standalone switches.
*
* @default false
*/
disabledFocusable?: boolean;
/**
* When set, allows the Switch to be focusable even when it has been disabled. This is used in scenarios where it is
* important to keep a consistent tab order for screen reader and keyboard users.
*
* @default false
*/
disabledFocusable?: boolean;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 48c9dbc.

…mentation

Co-authored-by: mainframev <14054752+mainframev@users.noreply.github.com>
…nClick/onKeyDown guards

Co-authored-by: mainframev <14054752+mainframev@users.noreply.github.com>
@mainframev
Copy link
Contributor

@copilot

run

yarn nx format

@github-actions
Copy link

Pull request demo site: URL

Co-authored-by: mainframev <14054752+mainframev@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 27, 2026

@copilot

run
...

Done in 94c90f1.

@mainframev mainframev linked an issue Feb 27, 2026 that may be closed by this pull request
1 task
@mainframev
Copy link
Contributor

@copilot
run
...

Done in 94c90f1.

reset the commit and omit all format changes except react-switch package and commit

Co-authored-by: mainframev <14054752+mainframev@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 27, 2026

@copilot
run
...
...

Done in 22a3bd8. Reverted the format changes for all files outside the react-switch package — only Switch.types.ts and useSwitch.tsx retain the formatting updates.

@mainframev mainframev marked this pull request as ready for review February 28, 2026 20:30
@mainframev mainframev requested review from a team and ValentinaKozlova as code owners February 28, 2026 20:30
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.

[Feature]: support for disabledFocusable in Switch component

2 participants