Skip to content

Commit

Permalink
Merge pull request #63 from alexstine/improve/dark-mode-a11y
Browse files Browse the repository at this point in the history
Dark mode toggle: Refactor label for better A11Y support for screen readers
  • Loading branch information
ianhodge authored Apr 6, 2023
2 parents d1c986d + f04431a commit 05aa429
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions components/DarkModeToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ const DarkModeToggle = () => {
};

return (
<label className="cursor-pointer relative">
<label className="cursor-pointer relative" htmlFor="dark-mode-toggle">
<div className="flex items-center">
<span className="absolute top-1 right-1 flex items-center h-4 pr-1">
<span className="absolute top-1 right-1 flex items-center h-4 pr-1" aria-hidden="true">
<MoonIcon />
</span>
<span className="absolute top-1 left-1 flex items-center h-4 pl-1">
<span className="absolute top-1 left-1 flex items-center h-4 pl-1" aria-hidden="true">
<SunIcon />
</span>
<input
type="checkbox"
id="dark-mode-toggle"
className="sr-only"
checked={!isDarkMode}
aria-label={"Dark Mode"}
onChange={toggleTheme}
/>
<div className="toggle-bg bg-toggle-light dark:bg-toggle-dark h-6 w-11 rounded-full"></div>
<div className="toggle-bg bg-toggle-light dark:bg-toggle-dark h-6 w-11 rounded-full" aria-hidden="true"></div>
<span className="sr-only">Dark Mode</span>
</div>
</label>
);
Expand Down

1 comment on commit 05aa429

@vercel
Copy link

@vercel vercel bot commented on 05aa429 Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.