-
Notifications
You must be signed in to change notification settings - Fork 0
π¨ Palette: Accessible Collapsibles #39
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
|
|
||
| ## 2025-04-29 - Accessible Collapsibles with Unique IDs | ||
| **Learning:** For accessible React interactive widgets (like tabs or collapsibles), it's important to use React's `useId` hook to generate unique IDs for `aria-controls` mappings. This ensures correct screen reader context and prevents ID collisions when multiple instances of the widget are rendered on the same page. | ||
| **Action:** Always use `useId` for mapping `aria-controls` to the corresponding `id` of the controlled element in custom interactive components. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| "use client"; | ||
|
|
||
| import { useState } from "react"; | ||
| import { useState, useId } from "react"; | ||
|
|
||
| interface WikiCollapsibleProps { | ||
| title: string; | ||
|
|
@@ -14,6 +14,7 @@ export function WikiCollapsible({ | |
| defaultOpen = true, | ||
| }: WikiCollapsibleProps) { | ||
| const [isOpen, setIsOpen] = useState(defaultOpen); | ||
| const contentId = useId(); | ||
|
|
||
| return ( | ||
| <div className="border border-wiki-border-light bg-wiki-offwhite"> | ||
|
|
@@ -22,11 +23,17 @@ export function WikiCollapsible({ | |
| <button | ||
| onClick={() => setIsOpen(!isOpen)} | ||
| className="text-wiki-link text-sm hover:underline" | ||
| aria-expanded={isOpen} | ||
| aria-controls={contentId} | ||
| > | ||
| [{isOpen ? "hide" : "show"}] | ||
| </button> | ||
| </div> | ||
| {isOpen && <div className="px-4 py-3">{children}</div>} | ||
| {isOpen && ( | ||
| <div id={contentId} className="px-4 py-3"> | ||
| {children} | ||
| </div> | ||
| )} | ||
|
Comment on lines
+26
to
+36
|
||
| </div> | ||
| ); | ||
| } | ||
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.
The toggle is missing
type="button". In this codebase, wiki UI buttons typically specifytype="button"to avoid accidental form submission when the component is used inside a (e.g., src/components/wiki/wiki-dropdown.tsx, src/components/wiki/barcode-scanner.tsx).