Skip to content

[switch] Fix incorrect role with slotProps.input#48469

Merged
mj12albert merged 2 commits into
mui:masterfrom
mj12albert:fix-switch-role
May 4, 2026
Merged

[switch] Fix incorrect role with slotProps.input#48469
mj12albert merged 2 commits into
mui:masterfrom
mj12albert:fix-switch-role

Conversation

@mj12albert
Copy link
Copy Markdown
Member

@mj12albert mj12albert commented May 4, 2026

Can be observed in the docs - they all incorrectly expose role="checkbox"

@mj12albert mj12albert added type: bug It doesn't behave as expected. scope: switch Changes related to the switch. priority: important This change can make a difference. labels May 4, 2026
@mj12albert mj12albert added this to the MUI X v9 milestone May 4, 2026
@mj12albert mj12albert marked this pull request as ready for review May 4, 2026 10:38
@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard Bot commented May 4, 2026

Deploy preview

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

Bundle size

Bundle Parsed size Gzip size
@mui/material ▼-24B(0.00%) ▼-9B(-0.01%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 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


Check out the code infra dashboard for more information about this PR.

@ZeeshanTamboli
Copy link
Copy Markdown
Member

Am I missing anything? I can't see role="checkbox" in the docs: https://mui.com/material-ui/react-switch/ demos

@mj12albert
Copy link
Copy Markdown
Member Author

Am I missing anything? I can't see role="checkbox" in the docs: https://mui.com/material-ui/react-switch/ demos

Screenshot 2026-05-04 at 7 31 52 PM

@mj12albert mj12albert modified the milestones: MUI X v9, Material UI v9.x May 4, 2026
Copy link
Copy Markdown
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

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

I am confused. I had added role="switch" in #46482. Did anything change after that?

@mj12albert
Copy link
Copy Markdown
Member Author

Did anything change after that?

Seems it's a regression from #48059slotProps.input replaces the whole internal input slot props object, so the role is lost whenever slotProps.input is involved

@mj12albert mj12albert added type: regression A bug, but worse, it used to behave as expected. and removed type: bug It doesn't behave as expected. labels May 4, 2026
@ZeeshanTamboli
Copy link
Copy Markdown
Member

ZeeshanTamboli commented May 4, 2026

slotProps.input replaces the whole internal input slot props object, so the role is lost whenever slotProps.input is involved

How do the other tests with getByRole("switch") still work? Just trying to understand here. Is this issue only when slotProps.input is provided? If yes, I don't see role="switch" in the docs for demos without slotProps.input.

@silviuaavram
Copy link
Copy Markdown
Member

@ZeeshanTamboli I think @mj12albert is fixing the case when slotProps is passed. The tests that have getByRole="switch" don't have it passed.

@mj12albert
Copy link
Copy Markdown
Member Author

Yep, many demos are spreading it like this:

const label = { slotProps: { input: { 'aria-label': 'Switch demo' } } };

<Switch {...label} defaultChecked />

Which isn't visible in the preview snippet so it's easy to miss that those are actually passing slotProps.input as well

@ZeeshanTamboli
Copy link
Copy Markdown
Member

Got it now. Thanks!

It’s a regression from #46482, where with slotProps.input it didn't add role="switch"—not from #48059.

@mj12albert mj12albert added v7.x needs cherry-pick The PR should be cherry-picked to master after merge. labels May 4, 2026
@mj12albert mj12albert enabled auto-merge (squash) May 4, 2026 15:46
@mj12albert mj12albert merged commit 52edadb into mui:master May 4, 2026
18 checks passed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Cherry-pick PRs will be created targeting branches: v7.x

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

Labels

accessibility a11y needs cherry-pick The PR should be cherry-picked to master after merge. priority: important This change can make a difference. scope: switch Changes related to the switch. type: regression A bug, but worse, it used to behave as expected. v7.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants