Skip to content

[Switch] added role to Span element #46318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

KirankumarAmbati
Copy link
Contributor

Fixes #45436

@zannager zannager added the component: switch This is the name of the generic UI component, not the React module! label Jun 13, 2025
@zannager zannager requested a review from siriwatknp June 13, 2025 03:15
@KirankumarAmbati
Copy link
Contributor Author

Hey @siriwatknp, please can you review this PR. If anything needs to be added, please let me know, I will update the PR. Thanks!

@@ -206,7 +206,7 @@ const SwitchBase = React.forwardRef(function SwitchBase(props, ref) {
centerRipple: true,
focusRipple: !disableFocusRipple,
disabled,
role: undefined,
role: 'switch',
Copy link
Member

Choose a reason for hiding this comment

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

I think the explicit role: undefined exist for specific fix.

The proper fix is to add role: 'switch' to Switch component. @sai6855 Would you mind checking on this?

This PR requires a test to ensure that the issue is fixed without introducing any regression.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIU, SwitchBase component uses ButtonBase as the root component, which automatically assigns role=button to Switch. So, to override that, we explicitly provide role=undefined as a prop.

But in our case, we want the role to be switch. So, I feel that updating SwitchBase role to switch is the right approach. But, it's just my thought process and I can be wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: switch This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Switch] disabled prop doesn't set aria-disabled on input element
4 participants