Exclusive Accordion
shadcn-htmx/exclusive-accordionFreeComponent
Scriptless single-open accordion: multiple native <details> elements share one `name` attribute so opening one auto-closes the others — the pure-HTML exclusive variant of the APG-scripted accordion. Zero JavaScript; the exclusivity survives with JS disabled. Ships in five flavours: Hono JSX (TypeScript), Jinja2 macros, Go html/template, Phoenix function component, and a raw HTML snippet.
Live preview
live · rendered by the registry
Rendered by shadcn-htmx on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shadcn-htmx.productdevbook.com/r/exclusive-accordion.jsonSource
1/** @jsxImportSource hono/jsx */2import type { PropsWithChildren } from "hono/jsx"3import { cn, type ClassValue } from "@/registry/lib/cn"45// Exclusive Accordion — shadcn-htmx, htmx v4 + Tailwind v4.6//7// The scriptless, single-open accordion. Several <details> elements share one8// `name` attribute, so the browser keeps exactly one open at a time: opening9// any item auto-closes the others. This is the pure-HTML exclusive variant of10// the APG-scripted accordion — ZERO JavaScript, no boot script, no site.js.11//12// shadcn upstream uses Radix Accordion (a JS state machine wiring buttons +13// regions with aria-expanded / aria-controls). We let the platform do it:14// - Click / Space / Enter toggles open (browser default on <summary>).15// - <summary> is implicitly role="button", focusable, with its text as the16// accessible name; the browser sets aria-expanded to mirror `open`.17// - <details name="..."> makes the group mutually exclusive natively. Per the18// HTML spec, if more than one grouped item carries `open`, only the FIRST19// in source order renders open — so we never produce an invalid state.20//21// This component differs from registry/ui/accordion.tsx (type="single"), which22// assigns the grouping `name` at runtime via public/site.js and layers the APG23// arrow-key contract on top. ExclusiveAccordion renders the `name` straight24// into the server HTML, so the exclusivity survives with JS disabled and there25// is no keyboard contract beyond what <summary> ships natively (Tab to focus,26// Enter / Space to toggle). That makes it the right pick for progressive-27// enhancement-first surfaces (docs FAQs, server-rendered settings panels).28//29// Refs:30// repos/mdn/files/en-us/web/html/reference/elements/details/index.md31// (`name` attribute — "give multiple <details> the same name value to32// group them. Only one of the grouped <details> can be open at a time …33// if multiple are given `open`, only the first in source order renders34// open." Also: `open` boolean, the `toggle` event, implicit role=group.)35// repos/mdn/files/en-us/web/html/reference/elements/summary/index.md36// (click / Space toggles parent <details>; display:list-item marker.)37// repos/aria-practices/content/patterns/accordion/ (the scripted contract we38// deliberately do NOT emulate here — see the note above.)39// repos/aria-practices/content/patterns/disclosure/ (native <details> is a40// … truncated
More from shadcn-htmx
All 83 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | shadcn-htmx | Components | Free | no deps | |
| Active Searchactive-search | shadcn-htmx | Components | Free | no deps | |
| Alertalert | shadcn-htmx | Components | Free | no deps | |
| Alert Dialogalert-dialog | shadcn-htmx | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | shadcn-htmx | Components | Free | no deps | |
| Auto Gridauto-grid | shadcn-htmx | Components | Free | no deps | |
| Autocompleteautocomplete | shadcn-htmx | Components | Free | no deps | |
| Autosize Textareaautosize-textarea | shadcn-htmx | Components | Free | no deps |
