-
Notifications
You must be signed in to change notification settings - Fork 0
🎨 Palette: Add aria-pressed to toggle buttons #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,9 +25,11 @@ export function applyTheme(theme) { | |
| } | ||
|
|
||
| if (toggleBtn) { | ||
| const nextThemeLabel = theme === 'light' ? '深色' : '淺色'; | ||
| const isLight = theme === 'light'; | ||
| const nextThemeLabel = isLight ? '深色' : '淺色'; | ||
| toggleBtn.setAttribute('aria-label', `切換至${nextThemeLabel}模式`); | ||
| toggleBtn.setAttribute('title', `切換至${nextThemeLabel}模式`); | ||
|
Comment on lines
+29
to
31
|
||
| toggleBtn.setAttribute('aria-pressed', isLight ? 'true' : 'false'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
| } | ||
|
|
||
| document.dispatchEvent(new CustomEvent('themechange', { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
aria-pressedto a button that already changes itsaria-labelto describe an action (e.g., "隱藏密碼") is an accessibility anti-pattern. A toggle button should either have a static label witharia-pressedto indicate state, or a dynamic label that changes to describe the action withoutaria-pressed. Mixing both can lead to confusing announcements like "Hide password, toggle button, pressed". Consider keeping the label static if you want to use the toggle button pattern.