Skip to content

Conversation

@KirankumarAmbati
Copy link
Contributor

@KirankumarAmbati KirankumarAmbati commented Jun 11, 2025

@zannager zannager added the scope: switch Changes related to the switch. 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!

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.

@mui-bot
Copy link

mui-bot commented Jul 3, 2025

Netlify deploy preview

https://deploy-preview-46318--material-ui.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/material ▼-11B(0.00%) ▼-2B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against bc89849

@ZeeshanTamboli ZeeshanTamboli changed the title [Switch] added role to Span element [Switch] Remove aria-disabled from root span Jul 3, 2025
@ZeeshanTamboli ZeeshanTamboli changed the title [Switch] Remove aria-disabled from root span [Switch][Checkbox][Radio] Remove aria-disabled from root span Jul 3, 2025
@ZeeshanTamboli
Copy link
Member

@KirankumarAmbati @siriwatknp Let's keep this PR focused on aria-disabled. The role="switch" discussion can happen separately. Also, role="switch" should be added on the <input> so we can keep the discussions separate.

In this PR, I removed aria-disabled from the root <span> of the Switch, Checkbox, and Radio components. Since SwitchBase is shared, this affects all three. As per my research, it's correct to remove it because aria-disabled has no effect on elements without a valid ARIA role.

The role="switch" issue is already tracked in #23216, and I’ve opened a PR for it: #46482.

@ZeeshanTamboli ZeeshanTamboli requested a review from siriwatknp July 3, 2025 14:50
@DiegoAndai DiegoAndai removed their request for review August 13, 2025 19:19
@ZeeshanTamboli
Copy link
Member

@siriwatknp Can you review this? See #46318 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility a11y scope: switch Changes related to the switch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants