Collapsible
shadcn-htmx/collapsibleFreeComponent
A single show/hide disclosure built on native <details>/<summary> — click, Space, or Enter toggle and the browser mirrors aria-expanded, all with zero JavaScript. A standalone disclosure, distinct from the grouped Accordion.
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/collapsible.jsonSource
1/** @jsxImportSource hono/jsx */2import type { PropsWithChildren } from "hono/jsx"3import { cn, type ClassValue } from "@/registry/lib/cn"45// Collapsible — shadcn-htmx, htmx v4 + Tailwind v4.6//7// shadcn upstream uses Radix Collapsible (a CollapsibleTrigger button + a8// CollapsibleContent region wired together with aria-expanded / aria-controls9// and JS state). We use the native HTML disclosure widget instead:10// <details><summary>Trigger</summary>...content...</details>11// so the platform gives us, with zero JS:12// - Click / Space / Enter toggles open (browser default on <summary>).13// - <summary> is implicitly role="button", focusable, with its text as the14// accessible name; the browser sets aria-expanded to mirror `open`.15// - The content is the accessible description of the summary.16//17// This is the WAI-ARIA Disclosure (Show/Hide) pattern: a single button that18// shows/hides one section of content. Distinct from Accordion — Collapsible19// is a standalone, single show/hide, NOT a group, so there is no `name`20// attribute and no exclusive grouping. No public/site.js hook is required:21// the entire keyboard contract (Enter / Space) is native to <summary>.22//23// Refs:24// repos/aria-practices/content/patterns/disclosure/disclosure-pattern.html25// (Keyboard: Enter / Space toggle; role=button; aria-expanded true/false)26// repos/mdn/files/en-us/web/html/reference/elements/details/index.md27// (`open` boolean; implicit ARIA role=group; toggle event)28// repos/mdn/files/en-us/web/html/reference/elements/summary/index.md29// (click/Space toggles parent <details>; display:list-item marker)3031type CollapsibleProps = PropsWithChildren<{32 // Pre-open the disclosure on initial render.33 open?: boolean34 disabled?: boolean35 class?: ClassValue36}>3738export function Collapsible(props: CollapsibleProps) {39 const { open, disabled, class: className, children, ...rest } = props40 return (41 <details42 data-slot="collapsible"43 data-disabled={disabled ? "true" : undefined}44 open={open}45 class={cn(46 "w-full",47 disabled && "pointer-events-none opacity-50",48 className,49 )}50 {...rest}51 >52 {children}53 </details>54 )55}5657type CollapsibleTriggerProps = PropsWithChildren<{ class?: ClassValue }>5859export function CollapsibleTrigger(props: CollapsibleTriggerProps) {60 const { class: className, children, ...rest } = props61 return (62 <summary63 data-slot="collapsible-trigger"64// … 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 |
