Skip to content

[Switch] added role to Span element #46318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mui-material/src/internal/SwitchBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const SwitchBase = React.forwardRef(function SwitchBase(props, ref) {
centerRipple: true,
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.

tabIndex: null,
},
});
Expand Down