Skip to content

a11y: light & dark mode checkbox doesn't announce state switches #7667

Description

@JoshuaKGoldberg

Have you read the Contributing Guidelines on issues?

Prerequisites

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

  1. Activate a screenreader such as NVDA or VoiceOver
  2. Tab over to the light/dark mode toggle
  3. 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

Self-service

  • I'd be willing to fix this bug myself.

Activity

  1. added
    bug
    status: needs triage
    on Jun 23, 2022
  2. added
    domain: a11y
    and removed
    status: needs triage
    on Jun 23, 2022
  3. Josh-Cena commented on Jun 23, 2022

    @Josh-Cena
    Collaborator

    I'm not sure how we are to fix this. aria-pressed definitely doesn't seem like a fit. Would aria-live="assertive" help?

  4. BenDMyers commented on Jun 23, 2022

    @BenDMyers
    Contributor

    aria-pressed could 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." Since aria-pressed is 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 for aria-live announcements, that could work.

  5. Josh-Cena commented on Jun 23, 2022

    @Josh-Cena
    Collaborator

    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.

  6. noobyogi0010 commented on Jul 30, 2022

    @noobyogi0010

    @Josh-Cena I would like to work on this issue if no one else is already working on it.
    Thanks!

  7. Josh-Cena commented on Jul 30, 2022

    @Josh-Cena
    Collaborator

    @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.

  8. noobyogi0010 commented on Jul 30, 2022

    @noobyogi0010

    @Josh-Cena Okay, I'll get started with it.
    Thanks!

  9. noobyogi0010 commented on Aug 11, 2022

    @noobyogi0010

    @Josh-Cena
    Will something like this be a good fix for this issue?
    (The red underlined text)
    a11yDocusaurusRef

    I used aria-pressed and set it as false for dark mode and true for light mode.

  10. slorber commented on Oct 12, 2022

    @slorber
    Collaborator

    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?

  11. 5 remaining items

  12. dawei-wang commented on Dec 20, 2022

    @dawei-wang
    Contributor

    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.

  13. slorber commented on Dec 22, 2022

    @slorber
    Collaborator

    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 region. 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.

    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"

  14. dawei-wang commented on Dec 22, 2022

    @dawei-wang
    Contributor

    By moving away, I mean focusing the screen reader on another part of the screen. By region, I meant the light/dark mode button.

  15. dawei-wang commented on Dec 22, 2022

    @dawei-wang
    Contributor

    Here's a video. I hope this makes it clearer:

    Docusaurus_screenreader_color_mode_demo.mp4
  16. Vishrut19 commented on May 18, 2023

    @Vishrut19

    Is this issue still open?

  17. aravind0543 commented on Oct 2, 2024

    @aravind0543

    @JoshuaKGoldberg i would like to work on this .Is there anyone working on it or would you assign it to me

  18. saravanamuthu1 commented on Feb 19, 2025

    @saravanamuthu1

    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

  19. slorber commented on Feb 20, 2025

    @slorber
    Collaborator

    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)

  20. WestonThayer commented on Mar 13, 2025

    @WestonThayer
    Contributor

    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-live on 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.

    <button title="Switch between dark and light mode (currently light mode)"></button>
    <!-- switches to... --->
    <button title="Switch between dark and light mode (currently dark mode)"></button>

    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 using aria-label or a different approach should be retested). Results:

    Results:
    • macOS Sequoia 15.3 VoiceOver + Safari 18.3
      • Announces the full accName and role when initially focused
      • Announces the new accName when button is invoked via VO+Space
      • Does not announce the new accName when button is invoked via Space or Enter (more on this below)
    • macOS Sequoia 15.3 VoiceOver + Chrome - not tested due to issues with Chrome
      • macOS Sequoia 15.3 VoiceOver + Chrome - not tested due to issues with Firefox
    • iOS 18.4 VoiceOver and Safari
      • Announces the full accName and role when initially focused
      • Announces the new accName when the button is invoked via double tap
    • NVDA 2024 + Chrome 132
      • Announces the full accName and role when initially focused
      • Announces the new accName when button is invoked via Space/Enter in focus mode
      • Announces the new accName when button is invoked via Space/Enter in browse mode
    • NVDA 2024 + Firefox 134
      • Announces the full accName and role when initially focused
      • Announces the new accName when button is invoked via Space/Enter in focus mode
      • Announces the new accName when button is invoked via Space/Enter in browse mode
    • JAWS 2025 + Chrome 132
      • Announces the full accName and role when initially focused
      • Announces the new accName when button is invoked via Space/Enter in focus mode
      • Announces the new accName when button is invoked via Space/Enter in browse mode
      • JAWS does seem to tire of announcing the same stuff if you toggle back one more time, then it will announce again next toggle. Weird
    • Talkback on Android 15 (Google Pixel 9)
      • Announces the full accName and role when initially focused
      • Does not announce the new accName when invoked via double tap

    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.

    Caveat: I tested latest SR/browser combinations. There are good arguments to check older versions as well (i.e. disabled users are more likely to be on older tech).

    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 with aria-pressed="true".

  21. slorber commented on Mar 14, 2025

    @slorber
    Collaborator

    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):

    Image

    According to my tests, NDVA behaves this way because:

    • We use live-live="polite"
    • We use aria-label and title with the exact same string (probably not a good idea)
    • Both strings get read twice, and twice again due to live-live="polite"
    • Using aria-pressed is misleading and not recommended cases where button name changes

    I've also noticed that without live-live="polite", VoiceOver would not announce when using enter/space, but only announces when using Cmd + Opt + Click (which is the "real" assistive click for VoiceOver). And VoiceOver would also announce twice when using live-live="polite" and Cmd + Opt + Click, but unlike NDVA I think it has a way to de-duplicate aria-label + title announcements that have the exact same text.


    Decisions

    It's not an easy problem considering screen readers behave differently, but:

    • aria-live doesn'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 users
    • aria-pressed doesn'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.
    • title may be useful to display a tooltip for sighted users, but it may not be useful to use the same label for both title and aria-label, leading to duplication in screen readers

    Note that YouTube is using the following for its play/stop player:

    <button aria-keyshortcuts="k" aria-label="Play Keyboard shortcut k" title="Play (k)">
    
    <button aria-keyshortcuts="k" aria-label="Pause Keyboard shortcut k" title="Pause (k)">

    My plan is to do the exact same:

    <button aria-label="Switch ... (currently dark mode) Keyboard shortcut k" title="dark mode">
    <button aria-label="Switch ... (currently light mode) Keyboard shortcut k" title="dark mode">
    <button aria-label="Switch ... (currently system mode) Keyboard shortcut k" title="system mode">

    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 title if 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 + Click

    This 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.

  22. WestonThayer commented on Mar 14, 2025

    @WestonThayer
    Contributor

    My mental model of aria-live matches yours, it's a bit like toasts.

    A few notes on your approach in #10987

    • One impact of using both aria-label and title is that aria-label becomes the accessible name and title is mapped to the accessible description. Here's how that shows up in a few different assistive technologies:
      • Speech recognition/control (like macOS Voice Control) would require a user to say something like click ARIA_LABEL in order to directly click the element. They won't be aware of the title value. 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 UX
      • macOS VoiceOver + Safari, iOS VoiceOver + Safari, NVDA + Chrome, NVDA + Firefox, Talkback + Chrome: all announce ARIA_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 design
      • JAWS + Chrome: announces ARIA_LABEL TITLE button in focus mode. A bit odd, I suspect there's a user preference to tweak that order
    • title offers 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 one
  23. slorber commented on Mar 17, 2025

    @slorber
    Collaborator

    Thanks for your feedback @WestonThayer

    Just to understand better, what do you suggest us to do concretely? Swap title and aria-label so that the concise text gets announced first?

    Regarding title tooltip, 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.

  24. WestonThayer commented on Mar 17, 2025

    @WestonThayer
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdomain: a11ygood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions