Shadcn Accordion
Five atomic Accordion parts with canonical group ownership, natural Tab order and explicit content lifetime.
Ordinary demos on this page explicitly use Shadcn Rhea, with matching examples. This does not change public compatibility defaults or imply complete browser, native-host or visual acceptance. Neutral Surface/Text atoms retain their own public semantics; the consumer composition supplies the family presentation theme.
This is a draft workspace family. The current source and synthetic-DOM tests do not establish browser/native, assistive-technology, material or GPUI completion.
Anatomy and ownership
Section titled “Anatomy and ownership”Compose Root → Item → Heading → Trigger, with Content beside Heading. Each Item needs a unique, stable, non-empty value. Root owns the selected key set; Item, Trigger and Content derive their facts. Nested Roots establish independent domains. Heading must contain only its controlling Trigger; place persistent secondary actions beside it.
The style projection consumes the corresponding Base atom. It does not create a private accordion, switch open state on focus, or inherit another Base protocol hook. APG and design systems are design references, not implementation upstreams.
JSON Props
Section titled “JSON Props”| Part | Props | Defaults and boundaries |
|---|---|---|
| Root | mode | single; multiple permits independent open items |
| Root | openItems, defaultOpenItems | string arrays; supplying openItems is controlled; default initializes once |
| Root | allowEmpty | true; false prevents closing the final selected key |
| Root | disabled | false; suppresses activation without rewriting owner input |
| Root | orientation, direction, loop | vertical, ltr, true; affect header navigation only |
| Item | value, disabled | required non-empty stable value; disabled defaults false |
| Heading | level | integer 1–6, default 3; choose the page hierarchy |
| Trigger | none | derives state from Item and Root |
| Content | keepMounted, region | both false; explicit hidden-view retention and optional landmark |
Input duplicates normalize; duplicate registered Item identities are rejected. Single mode takes the first supplied unique key. Unknown owner/default keys remain dormant for progressively mounted Items. Requests to missing keys are rejected. Uncontrolled keys retire after a previously registered Item disappears; changing value is removal/addition. In an empty group, allowEmpty=false cannot invent content. Controlled empty input remains the owner’s choice.
Exposes and controlled usage
Section titled “Exposes and controlled usage”Root exposes getOpenItems(), openCount, requestOpen(value, open, reason?) and the openChange signal with JSON payload { openItems, value, open, reason }. getOpenItems returns a copy; openCount includes dormant canonical keys. reason is pointer, keyboard or programmatic. Repeated no-op or disabled requests emit nothing.
A controlled request does not optimistically update any part. Accept it by supplying its openItems to Root. Adapter callbacks are the host projection of expose signals, not callback-valued Proto UI Props. Initialization, controlled sync, structural fallback and later default changes emit no openChange. Newer synchronous owner acceptance, including item removal during a request, wins over old notifications.
Keyboard and accessibility
Section titled “Keyboard and accessibility”Every enabled header remains in the natural Tab sequence, along with authored focusable content. Enter/Space toggles once. Vertical Up/Down or horizontal Left/Right navigate enabled headers; RTL reverses horizontal navigation. Home/End go to the first/last header. Navigation never changes openItems. loop=false keeps focus at the ends. Disabled headers are skipped; a required last-open header remains focusable while aria-disabled prevents collapse.
Heading declares heading/level. Trigger declares button, its content name, expanded, disabled and exact item-scoped controls. Content is labelled by its Trigger; region=true opts into a landmark. Use landmarks selectively, especially for large multiple-open groups. Native focus, assistive-technology output and platform fidelity still require their own evidence.
Presence, motion and safe layout
Section titled “Presence, motion and safe layout”Closed Content uses repeatable L1 detach by default. Logical instance identity persists; host child state and native view retention are not promised. keepMounted preserves a complete but hidden view. Content creates no autofocus, focus return or Tab stop. Closing while focus is inside authored content follows the host’s normal removal behavior; Accordion does not relocate it.
No delayed-close or transition timing API is introduced. Consumer-authored animation must preserve canonical open/hidden ownership. Style atoms wrap long labels, shrink within their container and contain horizontal content overflow. Page safe-area padding belongs to the containing layout. Actual narrow, 200% text, focus-outline and overflow screenshots remain a separate acceptance requirement.
Consumption and status
Section titled “Consumption and status”Import accordionRoot, accordionItem, accordionHeading, accordionTrigger and accordionContent from @proto.ui/prototypes-shadcn/accordion. Base also exports the matching asAccordion* authoring entries. All five atoms use the same API across Web Component, React, Vue and Vue 2.
Current-workspace CLI facade: proto-ui add react shadcn-accordion (also vue, vue2 and wc). Package publication/version availability is separate from this draft source.
Install
Section titled “Install”
npx @proto.ui/cli@latest add wc shadcn-accordion
Replace wc with react, vue or vue2 to generate the facade for that host.
Passing openItems selects controlled mode.
| Prop | Type | Default |
|---|---|---|
mode | 'single' 'multiple' | single |
defaultOpenItems | string[] | [] |
allowEmpty | boolean | true |
disabled | boolean | false |
orientation | 'vertical' 'horizontal' | vertical |
direction | 'ltr' 'rtl' | ltr |
loop | boolean | true |
These props belong to Root. Item requires value and defaults disabled to false. Heading defaults level to 3. Trigger has no props. Content defaults keepMounted and region to false.