Skip to content

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-panel GhostCollapsible wiring)
  • 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 via default.css)

Props and configuration ​

GhostAccordion (root) ​

PropTypeDefaultContract
type'single' | 'multiple''single'Single allows at most one open item; multiple allows many.
collapsiblebooleanfalseWhen type is single, allows closing the open item so none are expanded.
modelValuestring | string[] | undefinedundefinedControlled expansion. Omit for uncontrolled. Shape depends on type.
defaultValuestring | string[] | undefinedundefinedInitial expansion in uncontrolled mode.
headingLevel1 | 2 | 3 | 4 | 5 | 63Heading element wrapping each trigger (h1–h6).
disabledbooleanfalseDisables toggling on all items (root-level disable).

GhostAccordionItem ​

PropTypeDefaultContract
valuestringrequiredStable id for this panel.
disabledbooleanfalsePrevents toggling; combines with root disabled.

GhostAccordionTrigger ​

PropTypeDefaultContract
asGhostAccordionTriggerElement'button'Forwarded to GhostCollapsibleTrigger.

GhostAccordionContent ​

PropTypeDefaultContract
asGhostAccordionContentElement'div'Forwarded to GhostCollapsibleContent.
disableAnimationbooleanfalseForwarded 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": modelValue is string | undefined. undefined means no panel is open (only when collapsible is true, or initially uncontrolled with no defaultValue).
  • type="multiple": modelValue is string[]. 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 ​

  • GhostAccordion emits update:modelValue with [value: string | string[]].
  • Default slots on all parts are presentational unless noted.
  • GhostAccordionTrigger and GhostAccordionContent expose { element, focus, blur } via the underlying collapsible parts.

State model ​

  • Each item is open or closed. Root value coordinates which item(s) are open.
  • GhostAccordionItem renders GhostCollapsible with controlled :open derived from the root and forwards update:open to the root coordinator.
  • data-state="open" | "closed" comes from GhostCollapsible parts.
  • data-ghost-accordion-value is 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 GhostAccordionTrigger sits inside a heading (h1–h6 per headingLevel) and uses GhostCollapsibleTrigger disclosure semantics (aria-expanded, aria-controls, type="button").
  • Panels use GhostCollapsibleContent (hidden when collapsed, aria-labelledby to 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 tabindex mutation; nested accordions excluded).
  • Home / End: optional focus on first/last direct trigger.
  • Every header trigger remains in the sequential tab order.
  • In type="single" without collapsible, the open trigger sets aria-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" and data-ghost-accordion on the root.
  • data-part="header" on the heading wrapper; trigger/content use collapsible data-part values.
  • Themed CSS stacks items and reuses collapsible trigger/content surface styles. It applies only under .ghost-theme / .ghost-themed-scope or to the data-themed marker that the @ghostvue/themes root and item wrappers add. The behavior hooks above never opt an accordion into the theme, so a headless accordion stays unstyled when default.css is 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: useGhostAccordion value transitions.
  • Browser: basic and themed examples, axe clean, keyboard arrows between triggers.
  • Playground: AccordionReference section with unique copy.
  • Type: exported props and exposed types.

Documentation plan ​

  • docs/components/accordion.md with 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 themed GhostAccordionTrigger wrapper always sets data-themed on 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-theme or .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 themed GhostCollapsibleTrigger used outside an accordion. Headless accordions are unchanged even when default.css is loaded.
  • How it is painted. The trigger's ::after with content: '', so it adds no text. It is an --ghost-action-icon-size square (1.1em; the token is action.icon.size in packages/themes/tokens/semantic.json) filled with background: currentColor and cut to a chevron with clip-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: none and margin-inline-start: auto inside the existing inline-flex trigger, 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 when data-state="open". data-state and aria-expanded always change together on the trigger. CSS reads data-state, like the collapsible panel rules. Up and down do not mirror, so RTL needs no override. In non-collapsible type="single" mode, the open trigger has aria-disabled="true" and shows the open mark.
  • Motion. The 180° turn transitions rotate with --ghost-motion-duration-fast and --ghost-motion-easing-standard only under @media (prefers-reduced-motion: no-preference). With reduced motion the mark changes at once. GhostAccordionContent's disableAnimation does not affect the mark.
  • Forced colors. Forced colors replace backgrounds, so a background painted mark would disappear. Under @media (forced-colors: active) the ::after sets forced-color-adjust: none and paints in ButtonText, or GrayText when the trigger is disabled: :disabled for a native button, or [aria-disabled='true'] when as renders a non-button element, which GhostCollapsibleTrigger marks with aria-disabled instead of disabled. 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 as data-part="sort-indicator" on data table sort buttons and data-part="loading-indicator" on GhostButton. The consumer marks its own artwork aria-hidden="true" (and focusable="false" on SVG), as ADR 0013 rule 5 requires. The name is specific, so a leading data-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 sets content: none on the trigger's ::after removes 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 in content is 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-expanded on 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 ​

  1. Painted (browser). A themed trigger's ::after has computed content"", width and height equal to the resolved --ghost-action-icon-size, and a background equal to the trigger's color.
  2. State (browser). Enter, Space, and click on a trigger change the mark's computed rotate between the closed and open values in step with data-state and aria-expanded. This covers type="single" and type="multiple" and the locked open trigger.
  3. Reduced motion (browser). With reducedMotion: 'reduce' emulated, the mark's transition duration is 0s.
  4. Forced colors (browser). With forcedColors: 'active' emulated, the mark is still painted (forced-color-adjust: none, ButtonText), and a disabled item's mark uses GrayText, both for the default button trigger and for a trigger rendered with a non-button as (aria-disabled="true").
  5. Replacement (browser). A direct child with data-part="expand-indicator" turns the default off. The same attribute on a non-direct descendant, and data-part="icon", do not.
  6. Headless isolation (browser). A headless @ghostvue/vue accordion on a page that loads default.css, a headless accordion directly under a .ghost-theme host 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.
  7. 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.
  8. Examples and baselines. examples/accordion/billing-faq.vue marks its plus/minus SVG data-part="expand-indicator" so it does not show two marks. The accordion examples-visual baselines are updated with pnpm test:visual:docker.

Documentation plan ​

  • docs/components/accordion.md says the themed trigger shows a chevron by default and shows the plus/minus example as the way to replace it with data-part="expand-indicator", plus the one-line CSS that removes it.
  • The GhostAccordionTrigger styling hooks in the themed manifest list the ::after default and the expand-indicator opt-out.
  • A @ghostvue/themes Changeset.

Compatibility ​

  • @ghostvue/themes changes 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 marked data-part="expand-indicator". The Changeset says this in its migration line.
  • @ghostvue/vue is untouched: no markup, prop, slot, type, or manifest change. The themed GhostCollapsibleTrigger outside an accordion is not in this amendment and stays unmarked.