diff --git a/.jules/palette.md b/.jules/palette.md new file mode 100644 index 0000000..8d0659d --- /dev/null +++ b/.jules/palette.md @@ -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. diff --git a/src/components/wiki/wiki-collapsible.tsx b/src/components/wiki/wiki-collapsible.tsx index 5284dd8..a2a7871 100644 --- a/src/components/wiki/wiki-collapsible.tsx +++ b/src/components/wiki/wiki-collapsible.tsx @@ -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 (