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 is not correctly marked for screen reader #1561

Closed
2 tasks
Magsu opened this issue Sep 27, 2024 · 1 comment · Fixed by #1633
Closed
2 tasks

Switch is not correctly marked for screen reader #1561

Magsu opened this issue Sep 27, 2024 · 1 comment · Fixed by #1633
Assignees
Labels

Comments

@Magsu
Copy link

Magsu commented Sep 27, 2024

Provide a general summary of the issue here

The switch element is not interpreted correctly by some screen readers. For example, NVDA does not even recognize the element’s existence: It can be focused, but NVDA does not give any output. This is because the aria roles and properties have been set to the wrong element.
Note: This does not appear a problem for VoiceOver (Mac, iOS) or TalkBack (Android) due to them interpreting some information differently than PC screen readers (e.g. NVDA).

🤔 Expected Behavior?

When using a screen reader (e.g. NVDA) the elements label, role and state are announced correctly.

😯 Current Behavior

Some screen readers cannot interpret the element at all. It can be still toggled, but the screen reader provides no output for the user.

💁 Possible Solution

The aria properties and role are set to the wrong element (sl-switch):
image

Due to the shadow root delegating focus, the actual user focus is in the div with tabindex=”0”.

If I set role=”genetic” to the sl-switch (this should be the role it has initially, for this I’ve set it visibly, so I can get rid of the properties and roles that are set programmatically using elementInternals) and give the proper properties to the actually focused div, the element’s role and state are announced correctly.
Note: As div-tag does not support “checked” property, the checked property must be given as aria-checked=”true/false”. This an be set either in HTML or by using elementInternals.
Note2: This also means required and disabled statuses must be indicated using aria-disabled="true" and aria-required="true"
image

This, however, leaves us with one more problem: The element’s label is not announced at all. This is because the text is not connected to the switch element in any way.
We cannot use a label-tag, because it does not support giving a label to a div. Unless we’re doing some changes to the structure (this would also require changing CSS), we have a few options.
One way to connect is giving an id to the slot and connecting it to the button with aria-labelledby:
image

Another way is to give the label using aria-label:
image

Moving the actual text inside the correct focused element works too, but this does break the current styling:
image

🖥️ Steps to Reproduce

  1. Open a page with element (e.g. [Switch Basic](Open https://storybook.sanomalearning.design/?path=/story/form-switch--basic)
  2. Start a screen reader (not VoiceOver/TalkBack)
  3. Focus on the element and using the tab key

What browsers are you seeing the problem on? (only for bugs in code)

Chrome

If other, please specify.

No response

What operating system are you using?

Windows 10

👤 Your name

Valtteri Järvinen

🧢 Your product/team

External

🎨 Your Theme(s)

Sanoma Learning

Tasks

Preview Give feedback
@Magsu Magsu added bug Something isn't working development triage An issue needed triage labels Sep 27, 2024
@github-project-automation github-project-automation bot moved this to 📥 Incoming in SL Design System Team Sep 27, 2024
@DanielleRameau DanielleRameau removed the triage An issue needed triage label Oct 17, 2024
@DanielleRameau DanielleRameau moved this from 📥 Incoming to 🗃️ Backlog in SL Design System Team Oct 17, 2024
@DanielleRameau DanielleRameau moved this from 🗃️ Backlog to 🔜 Next up in SL Design System Team Oct 22, 2024
@anna-lach anna-lach self-assigned this Nov 13, 2024
@anna-lach
Copy link
Collaborator

Probably adding input to the switch component with type='checkbox' and role='switch' could improve the a11y:
https://www.w3.org/WAI/ARIA/apg/patterns/switch/examples/switch-checkbox/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants