GhostAccordion specification
Status: Proposed for GhostAccordion (GHO-34). Spec and implementation ship together; Zac approves both in PR review.
Purpose and user problems
GhostAccordion coordinates multiple in-flow disclosure panels so only one (or a chosen set) stays expanded at a time. Settings sections, FAQ lists, and filter groups need APG-correct accordion headers, predictable single vs multiple expansion, and arrow-key movement between section triggers without reimplementing useControllableState or duplicating GhostCollapsible open/close logic.
The component composes GhostCollapsible, useControllableState, useGhostId, so applications get controlled/uncontrolled expansion values, heading-wrapped triggers, and SSR-stable relationships.
Non-goals
- Standalone disclosure without accordion coordination (
GhostCollapsible). - Floating overlays, focus trapping, or modal semantics.
- Built-in chevron icons, drag-and-drop reorder, or lazy panel loading.
- A separate styling-hooks ADR contract (GHO-38).
Public API
Parts and exports
Headless exports from @ghostvue/vue:
GhostAccordion(root state and optional header keydown delegation)GhostAccordionItem(per-panelGhostCollapsiblewiring)GhostAccordionTrigger(heading-wrapped disclosure trigger)GhostAccordionContent(in-flow panel)useGhostAccordion(composable for expansion state)- Types in
ghost-accordion.ts
Themed exports from @ghostvue/themes:
GhostAccordion,GhostAccordionItem,GhostAccordionTrigger,GhostAccordionContent(plus re-exported types and styles viadefault.css)
Props and configuration
GhostAccordion (root)
| Prop | Type | Default | Contract |
|---|---|---|---|
type | 'single' | 'multiple' | 'single' | Single allows at most one open item; multiple allows many. |
collapsible | boolean | false | When type is single, allows closing the open item so none are expanded. |
modelValue | string | string[] | undefined | undefined | Controlled expansion. Omit for uncontrolled. Shape depends on type. |
defaultValue | string | string[] | undefined | undefined | Initial expansion in uncontrolled mode. |
headingLevel | 1 | 2 | 3 | 4 | 5 | 6 | 3 | Heading element wrapping each trigger (h1–h6). |
disabled | boolean | false | Disables toggling on all items (root-level disable). |
GhostAccordionItem
| Prop | Type | Default | Contract |
|---|---|---|---|
value | string | required | Stable id for this panel. |
disabled | boolean | false | Prevents toggling; combines with root disabled. |
GhostAccordionTrigger
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostAccordionTriggerElement | 'button' | Forwarded to GhostCollapsibleTrigger. |
GhostAccordionContent
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostAccordionContentElement | 'div' | Forwarded to GhostCollapsibleContent. |
disableAnimation | boolean | false | Forwarded to GhostCollapsibleContent. |
Native attributes fall through to each part root (trigger/content) or the accordion root.
v-model contracts
GhostAccordion owns modelValue via useControllableState:
type="single":modelValueisstring | undefined.undefinedmeans no panel is open (only whencollapsibleistrue, or initially uncontrolled with nodefaultValue).type="multiple":modelValueisstring[]. An empty array means none open.
Emits update:modelValue on every expansion change. Items wire GhostCollapsible in controlled mode from the root value.
Events, callbacks, slots, and exposed methods
GhostAccordionemitsupdate:modelValuewith[value: string | string[]].- Default slots on all parts are presentational unless noted.
GhostAccordionTriggerandGhostAccordionContentexpose{ element, focus, blur }via the underlying collapsible parts.
State model
- Each item is open or closed. Root value coordinates which item(s) are open.
GhostAccordionItemrendersGhostCollapsiblewith controlled:openderived from the root and forwardsupdate:opento the root coordinator.data-state="open" | "closed"comes fromGhostCollapsibleparts.data-ghost-accordion-valueis set on items for testing.
Disabled behavior
Root or item disabled prevents toggling on that item’s collapsible.
Consumer data
GhostAccordion holds no domain collections and never mutates consumer props.
Accessibility contract
Follows WAI-ARIA APG Accordion:
Semantics and relationships
- Each
GhostAccordionTriggersits inside a heading (h1–h6perheadingLevel) and usesGhostCollapsibleTriggerdisclosure semantics (aria-expanded,aria-controls,type="button"). - Panels use
GhostCollapsibleContent(hiddenwhen collapsed,aria-labelledbyto trigger when unlabeled).
Keyboard interaction
- Enter / Space on a trigger: toggle its panel (via
GhostCollapsibleTrigger). - ArrowDown / ArrowUp: optional focus move among direct item triggers (no
tabindexmutation; nested accordions excluded). - Home / End: optional focus on first/last direct trigger.
- Every header trigger remains in the sequential tab order.
- In
type="single"withoutcollapsible, the open trigger setsaria-disabled="true"(APG).
Focus behavior
Headers stay in document tab order; arrow keys optionally move among direct triggers only. Focus does not move into panel content on expand.
Rendering and customization
class="ghost-accordion"anddata-ghost-accordionon the root.data-part="header"on the heading wrapper; trigger/content use collapsibledata-partvalues.- Themed CSS stacks items and reuses collapsible trigger/content surface styles. It applies only under
.ghost-theme/.ghost-themed-scopeor to thedata-themedmarker that the@ghostvue/themesroot and item wrappers add. The behavior hooks above never opt an accordion into the theme, so a headless accordion stays unstyled whendefault.cssis loaded.
Environment behavior
SSR and hydration
Deterministic ids from useGhostId inside each GhostCollapsible. Optional header keydown listeners attach on the client in onMounted.
Composition
Reuses GhostCollapsible / GhostCollapsibleTrigger / GhostCollapsibleContent without copying open state, hidden, or disclosure keyboard activation.
Test plan
- Unit: single/multiple modes, collapsible single, controlled/uncontrolled value, disabled items, coordination when opening one closes another.
- Unit:
useGhostAccordionvalue transitions. - Browser: basic and themed examples, axe clean, keyboard arrows between triggers.
- Playground:
AccordionReferencesection with unique copy. - Type: exported props and exposed types.
Documentation plan
docs/components/accordion.mdwith basic, single-collapsible, multiple, themed examples via<GhostExample />.
Compatibility and release impact
New exports in @ghostvue/vue and @ghostvue/themes. Minor version Changeset.
Open architectural questions
None for GHO-34 scope.
Default disclosure mark amendment (proposed)
Important
Proposed. Not approved. This amendment adds a default disclosure mark to the themed GhostAccordionTrigger in @ghostvue/themes, under ADR 0013 rules 2 and 3. Rule 6 makes a new default mark a contract change, so it needs approval before any CSS ships. Until approval is recorded, the sections above stay authoritative and the themed trigger renders no mark. This revision delivers the contract and acceptance cases only. The data table expand mark is proposed alongside it and uses the same technique.
Why a default mark
Consumer feedback: a themed accordion trigger looks like a bordered row of text, not a control that opens a panel. Nothing shows that it expands or whether it is open. Today every consumer has to add their own chevron to make a themed accordion look finished. ADR 0013 rule 2 allows a themed wrapper to ship a small, replaceable default when the component looks broken without one. The Non-goals entry "Built-in chevron icons" still applies to headless @ghostvue/vue. On approval it is narrowed to the headless components.
Proposed contract
- Where it applies. The themed trigger only, keyed to the trigger's own opt-in:
.ghost-accordion-header > .ghost-collapsible-trigger[data-themed]. The themedGhostAccordionTriggerwrapper always setsdata-themedon the trigger, so the mark follows the trigger component, not the item: a headless trigger inside a themed item gets no mark, and a themed trigger inside a headless item does. Unlike the existing header rule, the mark does not also match under.ghost-themeor.ghost-themed-scope: child combinators stop a match across a component boundary but not a nested headless accordion that recreates the same header and trigger structure, so only the trigger's own marker keeps a headless accordion inside a theme host or themed panel unmarked. The direct-child header path keeps the mark off a themedGhostCollapsibleTriggerused outside an accordion. Headless accordions are unchanged even whendefault.cssis loaded. - How it is painted. The trigger's
::afterwithcontent: '', so it adds no text. It is an--ghost-action-icon-sizesquare (1.1em; the token isaction.icon.sizeinpackages/themes/tokens/semantic.json) filled withbackground: currentColorand cut to a chevron withclip-path: polygon(). It uses the same chevron shape as the data table's descending sort mark. The sort mark is the precedent for a clip-path mark that has no text. It uses no SVG, no new token, and no per-component color: the trigger's text color, disabled color, and theme mode all apply. - Placement.
flex: noneandmargin-inline-start: autoinside the existinginline-flextrigger, so the mark sits at the inline end of the row in both LTR and RTL. It stays inside the button, so the hit target and focus ring do not change. - State. The mark points down when
data-state="closed"and turns 180° to point up whendata-state="open".data-stateandaria-expandedalways change together on the trigger. CSS readsdata-state, like the collapsible panel rules. Up and down do not mirror, so RTL needs no override. In non-collapsibletype="single"mode, the open trigger hasaria-disabled="true"and shows the open mark. - Motion. The 180° turn transitions
rotatewith--ghost-motion-duration-fastand--ghost-motion-easing-standardonly under@media (prefers-reduced-motion: no-preference). With reduced motion the mark changes at once.GhostAccordionContent'sdisableAnimationdoes not affect the mark. - Forced colors. Forced colors replace backgrounds, so a background painted mark would disappear. Under
@media (forced-colors: active)the::aftersetsforced-color-adjust: noneand paints inButtonText, orGrayTextwhen the trigger is disabled::disabledfor a native button, or[aria-disabled='true']whenasrenders a non-button element, whichGhostCollapsibleTriggermarks witharia-disabledinstead ofdisabled. This matches the sort mark and the trigger's existing forced-colors disabled color.
Replacing or removing the mark
The trigger already renders its default slot inside the button, so a consumer does not need a new slot or prop.
- Replace. A decorative direct child of the trigger marked
data-part="expand-indicator"turns the default off for that trigger::not(:has(> [data-part='expand-indicator'])). This is the same pattern asdata-part="sort-indicator"on data table sort buttons anddata-part="loading-indicator"onGhostButton. The consumer marks its own artworkaria-hidden="true"(andfocusable="false"on SVG), as ADR 0013 rule 5 requires. The name is specific, so a leadingdata-part="icon"in the trigger label does not turn the default off. - Remove. The rule has zero specificity in
@layer ghostvue-theme, so any consumer rule that setscontent: noneon the trigger's::afterremoves it without!important. No prop is added for this.
Accessibility
- The mark is decorative and has no text (
content: ''). The trigger's accessible name still comes only from its slot content. A text glyph incontentis not allowed: generated content counts toward a name from content, so a glyph such as▾would be read as part of the heading button's name. aria-expandedon the trigger still carries the state for assistive technology. The mark is a visual copy of it and is never the only cue (ADR 0013 rule 5). Roles, heading structure, keyboard, and focus do not change.- The mark uses the trigger text color (
--ghost-surface-fg), which already passes WCAG 2 AA for text, so it meets the 3:1 non-text contrast minimum in every theme and mode.
Implementation acceptance cases
- Painted (browser). A themed trigger's
::afterhas computedcontent"", width and height equal to the resolved--ghost-action-icon-size, and a background equal to the trigger'scolor. - State (browser).
Enter,Space, and click on a trigger change the mark's computedrotatebetween the closed and open values in step withdata-stateandaria-expanded. This coverstype="single"andtype="multiple"and the locked open trigger. - Reduced motion (browser). With
reducedMotion: 'reduce'emulated, the mark's transition duration is0s. - Forced colors (browser). With
forcedColors: 'active'emulated, the mark is still painted (forced-color-adjust: none,ButtonText), and a disabled item's mark usesGrayText, both for the default button trigger and for a trigger rendered with a non-buttonas(aria-disabled="true"). - Replacement (browser). A direct child with
data-part="expand-indicator"turns the default off. The same attribute on a non-direct descendant, anddata-part="icon", do not. - Headless isolation (browser). A headless
@ghostvue/vueaccordion on a page that loadsdefault.css, a headless accordion directly under a.ghost-themehost and under a.ghost-themed-scope, and a headless accordion nested in a themed accordion's panel all have no painted::after. With mixed wrappers, a headless trigger inside a themed item has no mark and a themed trigger inside a headless item has one. - Name and axe (browser). Each trigger's accessible name equals its label text before and after toggling. Axe reports no violations with items open and closed.
- Examples and baselines.
examples/accordion/billing-faq.vuemarks its plus/minus SVGdata-part="expand-indicator"so it does not show two marks. The accordionexamples-visualbaselines are updated withpnpm test:visual:docker.
Documentation plan
docs/components/accordion.mdsays the themed trigger shows a chevron by default and shows the plus/minus example as the way to replace it withdata-part="expand-indicator", plus the one-line CSS that removes it.- The
GhostAccordionTriggerstyling hooks in the themed manifest list the::afterdefault and theexpand-indicatoropt-out. - A
@ghostvue/themesChangeset.
Compatibility
@ghostvue/themeschanges how it renders (minor Changeset). Every themed accordion trigger gains the mark. A themed accordion that already places its own chevron in the trigger shows two marks until that artwork is markeddata-part="expand-indicator". The Changeset says this in its migration line.@ghostvue/vueis untouched: no markup, prop, slot, type, or manifest change. The themedGhostCollapsibleTriggeroutside an accordion is not in this amendment and stays unmarked.