Skip to content
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

[Switch] disabled prop doesn't set aria-disabled on input element #45436

Open
DavidIvanov opened this issue Feb 27, 2025 · 6 comments
Open

[Switch] disabled prop doesn't set aria-disabled on input element #45436

DavidIvanov opened this issue Feb 27, 2025 · 6 comments
Assignees
Labels
accessibility a11y bug 🐛 Something doesn't work component: switch This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material

Comments

@DavidIvanov
Copy link

DavidIvanov commented Feb 27, 2025

Steps to reproduce

Add an MUI Switch to your document and give it the disabled prop.

Current behavior

Currently the aria-disabled is set on the span surrounding the input instead of on the input directly.
This causes accessibility issues with this rule
https://www.w3.org/WAI/WCAG22/Understanding/labels-or-instructions

Image

Expected behavior

The aria-disabled prop should be on the input directly.

Context

I want to be accessibility compliant with WCAG 2.1

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: Switch, aria-disabled, Accessibility

@DavidIvanov DavidIvanov added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 27, 2025
@mj12albert mj12albert added bug 🐛 Something doesn't work accessibility a11y component: switch This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material labels Feb 28, 2025
@mj12albert mj12albert changed the title Switch Component Aria disabled isnt applied on the input [Switch] disabled prop doesn't set aria-disabled on input element Feb 28, 2025
@mj12albert mj12albert removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 28, 2025
@mj12albert
Copy link
Member

mj12albert commented Feb 28, 2025

@DavidIvanov Thanks for reporting this ~

For now you can manually set aria-disabled using inputProps as a workaround:

<Switch
  disabled
  inputProps={{
    "aria-label": "My Switch",
    "aria-disabled": true,
  }}
/>

https://codesandbox.io/p/sandbox/divine-feather-sp5lkq?file=%2Fsrc%2FApp.js%3A11%2C9-17%2C11

@mj12albert mj12albert added the ready to take Help wanted. Guidance available. There is a high chance the change will be accepted label Feb 28, 2025
@mj12albert
Copy link
Member

mj12albert commented Feb 28, 2025

Added the ready to take label in case anyone wants to work on this before we get around to it.

Please reach out in this thread if you're interested ~

@dinesjo
Copy link

dinesjo commented Feb 28, 2025

Hi! I would like to work on this issue.

@mj12albert
Copy link
Member

@dinesjo Thanks ~ I've assigned you

@dinesjo
Copy link

dinesjo commented Mar 3, 2025

@mj12albert Here's an update on this:
I found a solution, but the issue is not isolated to just the Switch-component. More or less all input-components (Autocomplete, Button, Checkbox, ...) apply disabled without simultaneously adding aria-disabled="true".

I'm currently working on this as part of a university course on software engineering along with 2 others. In the following days we can find a way to systematically add this attribute to all such inputs and open a PR including unit tests once we are ready.

@mj12albert mj12albert removed the ready to take Help wanted. Guidance available. There is a high chance the change will be accepted label Mar 5, 2025
@siriwatknp
Copy link
Member

siriwatknp commented Mar 10, 2025

@DavidIvanov @mj12albert I believe that the solution to this issue is to reconsider the aria-disabled on the span element, not moving aria-disabled to input.

Based on MDN, the disabled is already used on input element. aria-disabled is not necessary.

I see two ways:

  • add appropriate role to the span. The closest would be role="switch"
  • remove the aria-disabled from the span.

After checked with Base UI Switch, using role="switch" looks like the proper solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility a11y bug 🐛 Something doesn't work component: switch This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants