Accordion
Collapsible content sections with single or multiple open items. Supports controlled and uncontrolled modes.
Installation
dgadd is not public on npm yet. Until the first release, pack @diffgazer/add from the repository and install that tarball into this app, which is what puts dgadd on pnpm exec.
The hosted registry is not public yet because r.b4r7.dev does not resolve. Use this source checkout or a local registry preview until the endpoint returns 200.
Diffgazer packages are not yet published to npm. Until the first release, pack @diffgazer/ui and @diffgazer/keys from the repository and install those tarballs.
UI components require Tailwind CSS v4. Local copy mode imports src/styles/styles.css; package mode uses @diffgazer/ui CSS once packages are available.
Usage
Examples
Multiple Open
Custom Handle
Source Variant
API Reference
Accordion
Accordion.Item
Accordion.Header
Accordion.Trigger
Accordion.Content
Data attributes
Accessibility
Keyboard Navigation
Built-in keyboard navigation via @diffgazer/keys navigation helpers. Arrow Up/Down moves focus between accordion triggers, Home/End jumps to first/last, Enter/Space toggles the focused item.
| Key | Action |
|---|---|
| ArrowUp / ArrowDown | Moves focus to the previous or next enabled trigger. |
| Home / End | Moves focus to the first or last enabled trigger. |
| Enter / Space | Toggles the focused trigger. |
Default (with keyboard support)
Notes
Requires @diffgazer/keys (package mode)
Accordion's arrow-key trigger navigation imports from the required @diffgazer/keys peer. Package consumers must install @diffgazer/keys with @diffgazer/ui; packages are not yet published to npm, so until the first release install both from locally packed tarballs. Importing @diffgazer/ui/components/accordion without keys fails at module load with an error naming the missing @diffgazer/keys package. Copy/dgadd consumers do not need the package — copy mode rewrites the keyboard helpers to local source.
Single vs Multiple
In single mode (default), only one item can be open. Set type='multiple' to allow several items open at once.
Collapsible
In single mode, collapsible defaults to true. With collapsible={false}, an accordion may still initialize with no open item, but once an item is selected, activating it again cannot close it.
Heading semantics
The APG accordion pattern requires each trigger to sit inside a heading. AccordionTrigger wraps itself in a default h3; set its headingLevel prop to match the surrounding document outline. Compose an explicit AccordionHeader to control the level instead — the trigger then skips its own wrapper so no doubled heading appears.
Keyboard Navigation
Arrow Up/Down moves focus between triggers. Home/End jumps to first/last trigger. Enter or Space toggles the focused item. Navigation wraps around.
Region role (opt-in)
AccordionContent accepts a region prop. When set, the open panel exposes role="region" with aria-labelledby pointing at its trigger. The APG accordion pattern lists this role as optional, so the default is off. Enable it for a small number of substantive panels (typically six or fewer) where each panel functions as its own landmark; leave it off when an accordion has many short items, since extra landmarks add noise to assistive-technology rotors.
Region role
AccordionContent accepts a region prop that opts the open panel into role="region" with aria-labelledby pointing at its trigger. The default is false.
The APG accordion pattern lists this role as optional ("MAY"), which is why the prop is opt-in rather than the default:
- Enable it when each panel functions as its own landmark and the accordion has a small number of substantive sections (typically six or fewer). Assistive-technology users can then jump straight to a panel via the landmark rotor.
- Leave it off when an accordion has many short items or stacks alongside other accordions on the page. Extra landmarks add noise to the rotor and dilute the value of true page-level regions.
Behavior:
- The role is only exposed while the panel is open. Collapsed panels never expose
role="region". - The accessible name comes from the trigger via
aria-labelledby; no extra label markup is required on the panel. - All other a11y wiring (
aria-expanded,aria-controls, native<button>semantics,inerton collapsed content) is unconditional and unaffected by this prop.
Source
Install via CLI: pnpm exec dgadd add ui/accordion. Keyboard hooks are included as standalone copies. For the full experience, use --integration keys.
Highlighted source loads after this disclosure opens. Browse the source repository.