react-toggle-dark-mode icon indicating copy to clipboard operation
react-toggle-dark-mode copied to clipboard

Not accessible by default

Open tknickman opened this issue 3 years ago • 1 comments

Because this uses an svg element, it is not keyboard accessible by default. You can fix this manually by wrapping the component in a button with a key handler, but it would be great if this was supported out of the box.

For example I have fixed this with:

<button
  onKeyDown={(e) => e.code === "Enter" && toggleTheme()}
  aria-label={`switch to ${
    colorTheme === themes.DARK ? "dark" : "light"
  } mode`}
>
  <DarkModeSwitch
    checked={colorTheme === themes.DARK}
    onChange={toggleTheme}
    ...
  />
</button>

This should be keyboard accessible (can be tabbed to, and selected with enter) by default.

tknickman avatar Feb 18 '22 14:02 tknickman

Because this uses an svg element, it is not keyboard accessible by default. You can fix this manually by wrapping the component in a button with a key handler, but it would be great if this was supported out of the box.

For example I have fixed this with:

<button
  onKeyDown={(e) => e.code === "Enter" && toggleTheme()}
  aria-label={`switch to ${
    colorTheme === themes.DARK ? "dark" : "light"
  } mode`}
>
  <DarkModeSwitch
    checked={colorTheme === themes.DARK}
    onChange={toggleTheme}
    ...
  />
</button>

This should be keyboard accessible (can be tabbed to, and selected with enter) by default.

Yes i'm also facing the same issue

VipEvel avatar Sep 22 '22 04:09 VipEvel