Skip to content

Navbar: theme toggle's visual order is ahead of its tab order #377

Closed

Description

@IanoNjuguna

Page or section

The site header (website/src/css/custom.css, right-hand navbar cluster) on every page.

Issue description

The theme toggle was moved to the left of the search field, and it was done with order rather than by changing the markup:

@media (min-width: 997px) {
  .navbar__items--right > div[class*='colorModeToggle'] {
    order: -1;
  }
}

order only repaints boxes. The markup is still search, GitHub, toggle, so the visual and the keyboard disagree:

order
what you see toggle, search, GitHub
what Tab visits search, GitHub, toggle
what a screen reader reads search, GitHub, toggle

Measured positions in the right cluster: toggle 867, search 915, GitHub 1171.

This breaks WCAG 2.4.3 (Focus Order) and 1.3.2 (Meaningful Sequence): a keyboard user watches the focus ring jump from the middle of the bar to the right, then back to the left.

Background: Docusaurus renders the toggle after the configured right-hand items, inside theme/Navbar/Content, and there is no config option to position it. order was the one-line shortcut.

Proposed change

Preferred, roughly fifteen lines and no framework internals in the repo:

  1. colorMode: { disableSwitch: true } in docusaurus.config.ts, which removes the built-in toggle.
  2. Swizzle theme/NavbarItem/ComponentTypes and register a custom item type, for example custom-colorModeToggle, that renders @theme/ColorModeToggle with useColorMode() from @docusaurus/theme-common.
  3. Place that item in navbar.items where it belongs, between the left items and the search item, and delete the order rule.

Then the markup order and the visual order are the same thing, and the drawer picks the same item up because navbar items render there too.

Fallbacks, if the custom item type turns out to fight the mobile drawer:

  • Swizzle theme/Navbar/Content and emit the toggle before the items. Works, but copies about a hundred lines of framework code that then has to be re-checked on every Docusaurus upgrade.
  • Keep order and accept the mismatch. Cheap, and wrong for keyboard and screen reader users.

Worth checking on the fix: the drawer still shows the toggle, colorMode.disableSwitch does not silently remove it from mobile, and the row order is unchanged at 1280 and 390.

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

    Low Prioritybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions