Accordion
shadcn-htmx/accordionFreeComponent
Collapsible stacked sections. Native <details>/<summary> + new HTML name attribute for zero-JS exclusive accordion. APG keyboard nav in site.js.
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/accordion.jsonSource
1/** @jsxImportSource hono/jsx */2import type { PropsWithChildren } from "hono/jsx"3import { cn, type ClassValue } from "@/registry/lib/cn"45// Accordion — shadcn-htmx, htmx v4 + Tailwind v4.6//7// shadcn upstream uses Radix Accordion. We use the native HTML8// <details><summary>...</summary>...</details>9// so the platform gives us:10// - Click / Space / Enter toggles open (browser default).11// - aria-expanded mirrors the open attribute (browser-set on <summary>).12// - <summary> is implicitly role="button" with accessible name from text.13//14// Native `<details name="...">` attribute (HTML Living Standard) makes the15// group exclusive — opening one item closes the others, no JS required.16// We use that for `type="single"`. For `type="multiple"` (the default) we17// omit the name attribute and every item can be expanded independently.18//19// Public/site.js adds the APG keyboard contract on top:20// - Down/Up Arrow: move focus between summaries in the same accordion.21// - Home / End: focus first / last summary.22//23// Refs:24// repos/mdn/files/en-us/web/html/reference/elements/details/index.md25// repos/mdn/files/en-us/web/html/reference/elements/summary/index.md26// repos/aria-practices/content/patterns/accordion/2728export type AccordionType = "single" | "multiple"2930type AccordionProps = PropsWithChildren<{31 // Required so the exclusive-accordion `name` attribute can scope items.32 id: string33 type?: AccordionType34 class?: ClassValue35}>3637export function Accordion(props: AccordionProps) {38 const { id, type = "multiple", class: className, children } = props39 return (40 <div41 id={id}42 data-slot="accordion"43 data-accordion44 data-type={type}45 data-group-name={type === "single" ? id : undefined}46 class={cn("w-full", className)}47 >48 {children}49 </div>50 )51}5253type AccordionItemProps = PropsWithChildren<{54 // Distinct value per item. Emitted as the `data-value` attribute so each55 // item is individually identifiable; the boot script does not derive any56 // aria-controls wiring from it. (Native <details>/<summary> is a disclosure57 // widget where aria-controls is optional per the WAI-ARIA Disclosure58 // pattern — repos/aria-practices/content/patterns/disclosure/.)59 value: string60 // Pre-open this item on initial render.61 open?: boolean62 disabled?: boolean63 class?: ClassValue64}>6566export function AccordionItem(props: AccordionItemProps) {67// … truncated
More from shadcn-htmx
All 83 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| 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 | |
| Avataravatar | shadcn-htmx | Components | Free | no deps |
