[switch] Fix incorrect role with slotProps.input by mj12albert · Pull Request #48469 · mui/material-ui (original) (raw)
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?
Did anything change after that?
Seems it's a regression from #48059 – slotProps.input replaces the whole internal input slot props object, so the role is lost whenever slotProps.input is involved
slotProps.inputreplaces the whole internal input slot props object, so the role is lost wheneverslotProps.inputis 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.
@ZeeshanTamboli I think @mj12albert is fixing the case when slotProps is passed. The tests that have getByRole="switch" don't have it passed.
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
Got it now. Thanks!
It’s a regression from #46482, where with slotProps.input it didn't add role="switch"—not from #48059.
Cherry-pick PRs will be created targeting branches: v7.x
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
[ Show hidden characters]({{ revealButtonHref }})