feat(react-switch): add disabledFocusable prop#35799
Open
Conversation
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 Feb 27, 2026
disabledFocusable prop
mainframev
reviewed
Feb 27, 2026
| }, | ||
|
|
||
| // DisabledFocusable (both checked and unchecked) - must come after :enabled: blocks to override them | ||
| '[aria-disabled="true"]': { |
Contributor
There was a problem hiding this comment.
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': {
Contributor
Author
There was a problem hiding this comment.
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; | ||
|
|
Contributor
There was a problem hiding this comment.
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; |
packages/react-components/react-switch/library/src/components/Switch/useSwitch.tsx
Outdated
Show resolved
Hide resolved
…mentation Co-authored-by: mainframev <14054752+mainframev@users.noreply.github.com>
…nClick/onKeyDown guards Co-authored-by: mainframev <14054752+mainframev@users.noreply.github.com>
Contributor
|
run yarn nx format |
|
Pull request demo site: URL |
Co-authored-by: mainframev <14054752+mainframev@users.noreply.github.com>
Contributor
Author
1 task
Contributor
Co-authored-by: mainframev <14054752+mainframev@users.noreply.github.com>
Contributor
Author
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.
disabledFocusablepatterns from Button/CheckboxdisabledFocusableprop toSwitch.types.ts(in SwitchProps and SwitchState)useSwitch.tsxto handledisabledFocusable:aria-disabled="true"instead ofdisabledattributeonChangeis unconditional (always calls user callback)onClickcallsev.preventDefault()to block state toggle whendisabledFocusableonKeyDownblocks Space/Enter whendisabledFocusableuseSwitchStyles.styles.tsto combine selectors instead of duplicatingdisabledFocusableinSwitch.test.tsxdisabledFocusablestory toSwitchDisabled.stories.tsxreact-switch.api.mdwith new APIyarn 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.