[Radio] Radio's ButtonBase
has role="button"
when using styled-components
#44185
Labels
component: ButtonBase
The React component.
component: radio
This is the name of the generic UI component, not the React module!
external dependency
Blocked by external dependency, we can’t do anything about it
package: styled-engine-sc
Specific to styled-components
Steps to reproduce
Link to live example: https://codesandbox.io/p/devbox/nervous-oskar-xx7s2l
Steps:
@mui/styled-engine
with@mui/styled-engine-sc
)<Radio />
componentCurrent 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:
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 theButtonBase
for a<Radio />
.Context
I think the problem is that
<SwitchBase />
passesrole={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#L177And 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
Search keywords: radio styled-components button
The text was updated successfully, but these errors were encountered: