Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/palette.md
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.
11 changes: 9 additions & 2 deletions src/components/wiki/wiki-collapsible.tsx
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;
Expand All @@ -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">
Expand All @@ -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}
>
Comment on lines 23 to 28
Copy link

Copilot AI Apr 29, 2026

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 specify type="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).

Copilot uses AI. Check for mistakes.
[{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
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

aria-controls points at contentId, but the controlled element is only rendered when isOpen is true. When collapsed, the DOM no longer contains an element with that id, so assistive tech may not be able to resolve the relationship. Consider always rendering the content container with a stable id and toggling visibility via hidden/CSS (and optionally role="region" + aria-labelledby) instead of unmounting it.

Copilot uses AI. Check for mistakes.
</div>
);
}
Loading