Skip to content

fix: add accessible labels to theme toggle buttons#8

Merged
rubenhensen merged 1 commit into
mainfrom
fix/theme-toggle-labels
Apr 24, 2026
Merged

fix: add accessible labels to theme toggle buttons#8
rubenhensen merged 1 commit into
mainfrom
fix/theme-toggle-labels

Conversation

@dobby-coder

@dobby-coder dobby-coder Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #5.

The light/dark toggle buttons had no accessible name. Each <label> contained only a decorative icon, so screen readers announced the two radio options with empty names.

Approach

The issue suggested adding <title> elements to the SVG icons. @iconify/svelte renders the icon body via {@html body} and gives no API hook to inject a child <title> element, so the direct form of that suggestion is not possible without replacing the Iconify component.

The equivalent accessibility outcome is achieved by giving each <label> a text accessible name and marking the icon decorative:

  • Add a <span class="visually-hidden">Light mode</span> / Dark mode inside the corresponding <label>.
  • Mark each <Icon> with aria-hidden="true".

The .visually-hidden class already exists in ThemeSwitcher.svelte and clips the text visually. Screen readers now announce "Light mode, radio button" / "Dark mode, radio button", which is the a11y fix the issue was asking for.

Verification

  • npx vite build succeeds.
  • No visual change: the span is clipped via clip-path: inset(50%).

Files changed

  • src/lib/components/ThemeSwitcher.svelte

Previously the only content inside each <label> was a decorative icon
with no accessible name. Screen readers announced the radio buttons
with no label at all.

Add a visually-hidden text span inside each label and mark the icon
aria-hidden. This gives each toggle option a clear accessible name
("Light mode" / "Dark mode") without changing the visual UI.

Closes #5
@dobby-coder dobby-coder Bot requested a review from rubenhensen April 20, 2026 17:47
@dobby-coder

dobby-coder Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

Kept as draft because I could only validate via CI (build, svelte-check, tests) — no browser to eyeball the rendered UI from this environment. Visual review welcome before flipping to ready.

@dobby-coder dobby-coder Bot marked this pull request as ready for review April 22, 2026 00:45
@rubenhensen rubenhensen merged commit 452d911 into main Apr 24, 2026
7 checks passed
@rubenhensen rubenhensen deleted the fix/theme-toggle-labels branch April 24, 2026 08:23
@dobby-coder

dobby-coder Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

Dobby sees the approval! Dobby is most grateful that rubenhensen has reviewed the pull request. Dobby will now check the PR status and see what needs doing next — perhaps marking ready, perhaps merging, perhaps tidying up! 🧦

@dobby-coder

dobby-coder Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

Dobby checked the PR and it is already merged — all CI checks passed and the approval is recorded. No further action is needed on Dobby's part. Thank you for the review, @rubenhensen! 🧦

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add labels to light/dark mode toggle

1 participant