Repository navigation
Labels
bugAn error in the Docusaurus core causing instability or issues with its executiondomain: a11yRelated to accessibility concerns of the default themegood first issueIf you are just getting started with Docusaurus, this issue should be a good place to begin.
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I'm using the latest version of Docusaurus.
- I have tried the
npm run clearoryarn clearcommand. - I have tried
rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages. - I have tried creating a repro with https://new.docusaurus.io.
- I have read the console error message carefully (if applicable).
Description
Following up from #6665: The color mode toggle now does correctly indicate what its state is with its label. But, when you activate it while using a screenreader, nothing narrates that it switched.
Discussed on stream with @BenDMyers on Twitch: https://www.twitch.tv/videos/1498962341.
Reproducible demo
https://typescript-eslint.io
Steps to reproduce
- Activate a screenreader such as NVDA or VoiceOver
- Tab over to the light/dark mode toggle
- Press Enter to trigger it
Expected behavior
There should be a narration, such as what's provided by aria-pressed.
See more here: https://sarahmhigley.com/writing/playing-with-state
Actual behavior
No narration.
Your environment
- Public source code: https://github.com/typescript-eslint/typescript-eslint
- Public site URL: https://typescript-eslint.io/
- Docusaurus version used: 2.0.0-beta.21
- Environment name and version (e.g. Chrome 89, Node.js 16.4): Chrome 102
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): Windows 10
Self-service
- I'd be willing to fix this bug myself.
Metadata
Metadata
Assignees
Labels
bugAn error in the Docusaurus core causing instability or issues with its executiondomain: a11yRelated to accessibility concerns of the default themegood first issueIf you are just getting started with Docusaurus, this issue should be a good place to begin.
Activity
Josh-Cena commentedon Jun 23, 2022
I'm not sure how we are to fix this.
aria-presseddefinitely doesn't seem like a fit. Wouldaria-live="assertive"help?BenDMyers commentedon Jun 23, 2022
aria-pressedcould be a fit if the toggle button's name were something like "Enable dark mode" — that way, as you toggle dark mode, you'd get announcements along the lines of "Enable dark mode, pressed" or "Enable dark mode, not pressed." Sincearia-pressedis an ARIA state attribute, it should be reliably announced when changed, unlike the accessible name as the linked Sarah Higley article points out.The button itself probably shouldn't receive
aria-live, since you'll have a mismatch of roles. If Docusaurus already has a mechanism foraria-liveannouncements, that could work.Josh-Cena commentedon Jun 23, 2022
Yes, but our button is light/dark instead of dark/not dark, so pretty sure that's not
aria-pressed. I'm just not sure how to force the screen reader to announce the change in button title.noobyogi0010 commentedon Jul 30, 2022
@Josh-Cena I would like to work on this issue if no one else is already working on it.
Thanks!
Josh-Cena commentedon Jul 30, 2022
@noobyogi0010 Since it hasn't had any activities in the last month, you can assume no-one is working on it and just go ahead.
noobyogi0010 commentedon Jul 30, 2022
@Josh-Cena Okay, I'll get started with it.
Thanks!
noobyogi0010 commentedon Aug 11, 2022
@Josh-Cena

Will something like this be a good fix for this issue?
(The red underlined text)
I used
aria-pressedand set it as false for dark mode and true for light mode.fix: Announce theme switches when using screen reader. meta#7667
fix(theme): announce theme switches when using screen reader. #7667 (#…
slorber commentedon Oct 12, 2022
I think there's an issue with our accessibility fix.
When we navigate from one page to another, triggering a global layout unmount/remount (ie navigating from homepage to docs or to blog), the dark mode switch will announce itself on navigation.
We should probably only make it announce after having been pressed once no?
5 remaining items
fix(theme): announce theme switches when using screen reader. #7667 (#…
dawei-wang commentedon Dec 20, 2022
Another problem with the accessibility fix is that the screen reader will continue to announce that the page is in dark mode or light mode for five or six times if the user does not move away from the light/dark mode button. I am able to reduce the announcements to two times if I remove aria-live="polite" from the web inspector. I expected the states to be announced one time on change only.
slorber commentedon Dec 22, 2022
I'm not sure to understand. By chance are you able to record a video or something that could make it clearer?
What do you mean by "move away from the region"
dawei-wang commentedon Dec 22, 2022
By moving away, I mean focusing the screen reader on another part of the screen. By region, I meant the light/dark mode button.
dawei-wang commentedon Dec 22, 2022
Here's a video. I hope this makes it clearer:
Docusaurus_screenreader_color_mode_demo.mp4
Vishrut19 commentedon May 18, 2023
Is this issue still open?
aravind0543 commentedon Oct 2, 2024
@JoshuaKGoldberg i would like to work on this .Is there anyone working on it or would you assign it to me
saravanamuthu1 commentedon Feb 19, 2025
Is this issue is still open? Because i cloned i used voice over. it was working well. the voice over said light mode and dark mode correclty. Can anybody clarify this? If the issue is closed, please close it
slorber commentedon Feb 20, 2025
This issue is still open because we are still not sure what to do, see also #8569 (comment)
This requires investigations to see the behavior of various screen readers
But it's probably not worth it to do now considering we are likely moving away from a checkbox in favor of something that allows resetting to OS theme setting (#8074)
WestonThayer commentedon Mar 13, 2025
Chiming in, @slorber linked me. I work on accessibility professionally at Assistiv Labs and can hopefully offer some advice. I probably lack some docusaurus context, so please forgive me if I end up off base.
If you stuck with the current UI paradigm (ignoring the type of approach outlined in #8074)
The button currently has
aria-liveon it. I wouldn't recommend this approach, especially when the element isn't in the initial server HTML. Screen readers have long standing compatibility issues with dynamically added live regions, more here: https://tetralogical.com/blog/2024/05/01/why-are-my-live-regions-not-working/. I'm not saying that the live region isn't currently working correctly, just that I've gotten so frustrated with live regions on dynamic elements in the past that I always rip them out when I see them.Exploring the initial approach
My first thought was to validate what I assume the approach was at the start of this issue: a button with an accessible name that updated after it's invoked to reflect what it would do next.
There are some good articles on this approach: https://adrianroselli.com/2020/12/be-careful-with-dynamic-accessible-names.html (Adrian has a wealth of knowledge) and https://sarahmhigley.com/writing/playing-with-state/ (mentioned in the initial issue). Their premises are still accurate, but the testing is several years out of date, so I created a minimal Codepen to try the approach (changing accName via
title, Sarah's post suggests usingaria-labelor a different approach should be retested). Results:Results:
Comparing to Sarah's 2019 testing, it looks like only JAWS has improved.
Zooming out, the end of Sarah's article contests the premise of this issue a bit — is it a problem that a screen reader doesn't announce the result of invoking the theme button? She argues that it is not a problem for a play/pause button at least. I can see her point.
Maybe you could end here if you accept that argument and are OK with it effecting only Talkback.
Applying a live region
It seems hard to argue that a quick screen reader announcement of the successful theme change would be undesirable as opposed to silence.
Live regions are one way to get screen readers to announce things. As noted in the post above, they're most stable when you put the DOM element for them in the initial server HTML and only have 1 per page.
You could put a message in that live region when invoking the theme button. This is essentially the strategy used by https://adrianroselli.com/2021/01/multi-function-button.html
It works, but now you've got 2 things happening at once: the live region and the accName change of the button. This is one cause of announcement repetition like #7667 (comment) (you can repro announcement repetition with Adrian's example and macOS VoiceOver+Safari by invoking the button with VO+Space instead of Space/Enter)
Could you hack around this? Defer the accName change? Don't change the accName? I feel like this starts going down a bad rabbit hole.
If you switched UI paradigms (as in #8074)
I'm assuming the idea is to do something like #8074 (comment)
I mean if you do a standard
<select>I think that's about as tried and true in terms of accessible and screen reader supported as you can get. Custom dropdowns are also pretty battle tested. Announcing the state change as described in this issue is sidestepped since both UI paradigms either shift the control's value or move focus to different controls.Other ideas
FWIW check out the theme switcher at the bottom of https://adrianroselli.com/. 3 buttons (light, dark, unset), each with
aria-pressed, only one witharia-pressed="true".slorber commentedon Mar 14, 2025
Hi @WestonThayer and thanks for your feeback
I'm in the process of adding a 3rd value to that button:
We could eventually move to a dropdown menu in the future, but it may be a more disruptive change for our users/UX, and I prefer to do that later eventually.
Regarding
aria-live="polite"that we currently use, we are a SSG framework so the live region is available on the initial HTML, but I don't think it makes sense to ever announce it on page load. Afaik it's not the case with either NDVA/VoiceOver, maybe it would be if we used "assertive"?However, a problem we have with NDVA is that it announces the same thing multiple times (current live implementation on docusaurus.io):
According to my tests, NDVA behaves this way because:
live-live="polite"aria-labelandtitlewith the exact same string (probably not a good idea)live-live="polite"aria-pressedis misleading and not recommended cases where button name changesI've also noticed that without
live-live="polite", VoiceOver would not announce when using enter/space, but only announces when usingCmd + Opt + Click(which is the "real" assistive click for VoiceOver). And VoiceOver would also announce twice when usinglive-live="polite"andCmd + Opt + Click, but unlike NDVA I think it has a way to de-duplicatearia-label+titleannouncements that have the exact same text.Decisions
It's not an easy problem considering screen readers behave differently, but:
aria-livedoesn't seem a good fit. It's not really meant to be applied to buttons and interactive elements. My mental model for it is more like a global empty container to provide dynamic feedback announcement, similar to UI toasts for sighted usersaria-presseddoesn't seem a good fit. MDN doesn't recommend it for buttons that change their text/aria-label as you press them, like it's the case here. There's a possible "mixed" state value for tri-state toggles, but I'm not sure it's a good idea to use it to represent the new "system" state we are introducing.titlemay be useful to display a tooltip for sighted users, but it may not be useful to use the same label for bothtitleandaria-label, leading to duplication in screen readersNote that YouTube is using the following for its play/stop player:
My plan is to do the exact same:
Reading "dark mode" + "switch between dark and light mode (currently dark mode)" is less annoying duplication than twice the same long sentence. Eventually, we could remove the
titleif needed, but I think it's still useful to keep it.Similar to YouTube, nothing will be announced for users using VoiceOver with Enter, but it will be announced when using the "real" assistive click
Cmd + Opt + ClickThis is what I'm implementing in:
I'm going to consider this issue closed. Even if the solution is not perfect, it's probably good enough for the right tradeoff for users of various screen readers. Unfortunately, I can't test on JAWS easily.
WestonThayer commentedon Mar 14, 2025
My mental model of
aria-livematches yours, it's a bit like toasts.A few notes on your approach in #10987
aria-labelandtitleis thataria-labelbecomes the accessible name andtitleis mapped to the accessible description. Here's how that shows up in a few different assistive technologies:click ARIA_LABELin order to directly click the element. They won't be aware of thetitlevalue. Just an FYI. Voice control UX for icon buttons has always been tricky (how will a user know which name to say?), which is why most voice control software offers alternative mechanisms (a user can say "show numbers", which adds an overlay on the UI with a number for each element, then "click NUMBER" to avoid having to know an element's accessible name). Not to say good accessible names for icon buttons don't streamline the voice control UXARIA_LABEL button TITLE, which is the common convention (accName is announced first, then role, then a description if one is present. The idea is to front load the concise information so a user can quickly skip past the element if it's not what they're looking for). Note that NVDA may not announce the accDescription in browse mode, that's by designARIA_LABEL TITLE buttonin focus mode. A bit odd, I suspect there's a user preference to tweak that ordertitleoffers a tooltip for sighted users. It goes against the spirit of WCAG SC 1.4.13 Content on Hover or Focus, even though it doesn't fail it b/c of the exception outlined there for user agent functionality. It still gets in the way of users though. Sarah once again has a good post if you're curious https://sarahmhigley.com/writing/tooltips-in-wcag-21/. This fix here would be to roll your own tooltip that works with keyboard and meets 1.4.13's design guidelines or find a library with oneslorber commentedon Mar 17, 2025
Thanks for your feedback @WestonThayer
Just to understand better, what do you suggest us to do concretely? Swap
titleandaria-labelso that the concise text gets announced first?Regarding
titletooltip, in the future we may add our own tooltip but I'd prefer to have a simple non-JS implementation, probably using the new CSS anchor positioning feature.WestonThayer commentedon Mar 17, 2025
A JS-less accessible tooltip would definitely be an improvement.
I can’t suggest swapping aria-label and title, I was just sharing that information so you were clear on which aspects of the UX each controlled in this scenario.
Some usability testing with disabled folks would be a great way to hone the control, but I know that’s probably not realistic in this case. I’d point you towards some public usability data for this type of control, but I’m unfortunately not aware of any. It seems like an emerging UI pattern, a tri-state icon button to control light/dark theme. I’m struggling to think of where I’ve seen other tri-state buttons on the web.