Description
Steps to reproduce
Link to live example: https://codesandbox.io/p/devbox/nervous-oskar-xx7s2l
Steps:
- Use mui together with styled-components (i.e. aliasing
@mui/styled-engine
with@mui/styled-engine-sc
) - Use a
<Radio />
component
Current behavior
The radio's ButtonBase has a role="button"
. This leads to an accessibility violation since there is a radio inside of a button.
The HTML basically looks like this:
<span
class="MuiButtonBase-root MuiRadio-root [...]"
role="button">
<input class="sc-egkSDF jccrsl PrivateSwitchBase-input" type="radio">
<span class="sc-fAUdSK cyWAma">
<svg>[...]</svg>
</span>
<span class="MuiTouchRipple-root-hfoSaC iZusHU MuiTouchRipple-root"></span>
</span>
Note that there is a role="button"
on the outermost <span>
. This should not be there and is in fact not there if you use the "regular" emotion adapter for @mui/styled-engine
.
Expected behavior
There is no role="button"
on the ButtonBase
for a <Radio />
.
Context
I think the problem is that <SwitchBase />
passes role={undefined}
to the <SwitchBaseRoot />
(which is a styled <ButtonBase />
) here: https://github.com/mui/material-ui/blob/master/packages/mui-material/src/internal/SwitchBase.js#L177
And I guess that styled-components just swallows properties with undefined
values (since version 6?).
It used to work with mui v5 and styled-components v5.
This bug also affects other components that use <SwitchBase />
(like <Checkbox />
or <Switch />
).
Your environment
npx @mui/envinfo
System:
OS: Linux 6.1 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
Binaries:
Node: 20.11.0 - /usr/local/bin/node
npm: 10.2.4 - /usr/local/bin/npm
pnpm: 8.15.1 - /usr/local/share/npm-global/bin/pnpm
Browsers:
Chrome: Not Found
npmPackages:
@mui/core-downloads-tracker: 6.1.5
@mui/envinfo: 2.0.28 => 2.0.28
@mui/material: ^6.1.5 => 6.1.5
@mui/private-theming: 6.1.5
@mui/styled-engine: 6.1.5
@mui/styled-engine-sc: ^6.1.5 => 6.1.5
@mui/system: 6.1.5
@mui/types: 7.2.18
@mui/utils: 6.1.5
@types/react: 18.3.11 => 18.3.11
react: 18.3.1 => 18.3.1
react-dom: 18.3.1 => 18.3.1
styled-components: ^6.1.13 => 6.1.13
Search keywords: radio styled-components button