GhostCollapsible specification
Status: Proposed for GhostCollapsible (GHO-86). Spec and implementation ship together; Zac approves both in PR review.
Amendment (approved 2026-12-03): a
variantprop on the themedGhostCollapsibleContentis recorded in the Content variant amendment. The maintainer @zprue743 approved it in PR review on 2026-12-03.
Purpose and user problems
GhostCollapsible is an accessible disclosure primitive: a trigger control expands or collapses associated content in place. Immediate consumers include DataTable expandable rows and grouped table sections where content must stay in document order, not float or trap focus.
The component composes useControllableState and useGhostId so applications get controlled/uncontrolled open state, deterministic id / aria-controls relationships, and SSR-stable markup without reimplementing disclosure wiring.
Non-goals
- Accordion coordination (only one open panel, roving focus, or arrow-key navigation). That belongs to a future
GhostAccordionbuilt onGhostCollapsible. - Floating overlays, portaling, focus trapping, or modal semantics (
GhostPopover,GhostDialog). - DataTable row expansion state machines or server-driven lazy load. Consumers own data; this primitive only toggles visibility.
- Built-in heading styles, chevron icons, or animation presets beyond optional theme CSS driven by
data-stateandprefers-reduced-motion.
Public API
Parts and exports
Headless exports from @ghostvue/vue:
GhostCollapsible(root state and context provider; renderless)GhostCollapsibleTrigger(disclosure button)GhostCollapsibleContent(in-flow panel hidden when collapsed)useGhostCollapsible(composable with reactive open state, controls, and IDs)- Types:
GhostCollapsibleProps,GhostCollapsibleSlotProps,GhostCollapsibleTriggerElement,GhostCollapsibleTriggerProps,GhostCollapsibleTriggerExposed,GhostCollapsibleContentElement,GhostCollapsibleContentProps,GhostCollapsibleContentExposed,UseGhostCollapsibleOptions,UseGhostCollapsibleReturn,GhostCollapsibleContext
Themed exports from @ghostvue/themes:
GhostCollapsible,GhostCollapsibleTrigger,GhostCollapsibleContent(plus re-exported types and styles viadefault.css)
Props and configuration
GhostCollapsible (root)
| Prop | Type | Default | Contract |
|---|---|---|---|
open | boolean | undefined | undefined | Controlled open state. Omit for uncontrolled mode. |
defaultOpen | boolean | false | Initial open state in uncontrolled mode. |
disabled | boolean | false | When true, the trigger cannot toggle open state (root-level disable). |
GhostCollapsibleTrigger
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostCollapsibleTriggerElement (Component | string) | 'button' | Element tag or component (for example GhostButton). |
disabled | boolean | false | Prevents toggling when true or when the root is disabled. Uses native disabled on <button> and aria-disabled="true" otherwise. |
GhostCollapsibleContent
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostCollapsibleContentElement (Component | string) | 'div' | Element tag or component for the panel. |
disableAnimation | boolean | false | When true, sets data-animation="off" so theme height transitions are skipped even when motion is allowed. |
Native attributes and listeners fall through to the rendered root element.
v-model contracts
GhostCollapsible owns open via useControllableState:
- When
openisundefined(omitted), internal state starts atdefaultOpenand updates on user toggles while still emittingupdate:open. - When
openisboolean,update:openis emitted and the consumer owns the state update.
Events, callbacks, slots, and exposed methods
GhostCollapsibleemitsupdate:openwith[open: boolean].GhostCollapsibledefault slot receives{ open: boolean, toggle: () => void }.GhostCollapsibleTriggerandGhostCollapsibleContentexpose{ element: HTMLElement | null, focus(options?: FocusOptions): void, blur(): void }.
State model
- Two binary states:
'closed'and'open'. GhostCollapsibleContentstays mounted in document order. When closed it uses the nativehiddenattribute (notv-if) so layout identity is stable for tables and SSR.data-state="open" | "closed"is set on trigger and content.data-animation="off"is set on content whendisableAnimationistrue.
Loading, empty, disabled, read-only, and error states
GhostCollapsibleTrigger honors root and local disabled. Disabled triggers ignore click and disclosure keyboard activation.
Consumer data
GhostCollapsible holds no domain collections and never mutates consumer props.
Accessibility contract
Follows WAI-ARIA APG Disclosure:
Semantics and relationships
GhostCollapsibleTriggerrenderstype="button"(whenas="button"),id(fromuseGhostId, overridable by consumerid),aria-expanded="true" | "false",aria-controls="<contentId>",data-part="trigger", anddata-state="open" | "closed". Noaria-haspopup.GhostCollapsibleContentrendersid(matchingaria-controls),hiddenwhen closed,data-part="content",data-state="open" | "closed", andaria-labelledby="<triggerId>"by default unless the consumer providesaria-labeloraria-labelledby.
Keyboard interaction
- Trigger (button host): native
EnterandSpacetoggle (no extra handler required on<button>). - Trigger (non-button host with
role="button"):EnterandSpacetoggle unless disabled or default-prevented on a consumer handler. - Content: no roving keys; focus moves normally through focusable descendants when the panel is open and visible.
Focus behavior
- Toggling does not move focus into content automatically (disclosure pattern).
- Focus remains on the trigger unless the consumer moves it.
Assistive technology expectations
- Collapsed content is removed from the accessibility tree via
hiddenand hidden from sighted users viadisplay: nonefrom the user agent or theme CSS.
Rendering and customization
- Headless parts use classes
ghost-collapsible-triggerandghost-collapsible-contentfor theme recipes. - Theme CSS may animate open/close using
data-stateand semantic--ghost-motion-*tokens, gated with@media (prefers-reduced-motion: reduce).
Environment behavior
SSR and hydration
- Deterministic
idvalues fromuseGhostIdpopulatearia-controlson the server. - Closed collapsibles render the content node with
hiddenin SSR HTML. - No
window/documentaccess during setup of root state or IDs.
Mobile and touch
- Trigger uses native click activation; no custom gestures.
Performance
- Content remains one DOM subtree; toggling only flips
hiddenand ARIA state.
Composition
- Reuses
useControllableState,useGhostId, and theas+inheritAttrs: falseattribute-splitting pattern fromGhostPopover/GhostDialogtriggers.
Test plan
- Vue: uncontrolled and controlled
open,disabledon root and trigger,aria-expanded/aria-controls/hidden, SSR render, cleanup on unmount, exposedelement/focus/blur. - Browser: keyboard toggle, axe on examples, playground disclosure exercise.
- Type: public exports consumed from themed and headless entry points.
Documentation plan
- API reference (
docs/components/collapsible.md), basic and themed examples, and playgroundCollapsibleReferencewith unique copy.
Compatibility and release impact
New minor export from @ghostvue/vue and @ghostvue/themes. Requires Changeset.
Open architectural questions
None for the minimal disclosure scope; accordion coordination is explicitly out of scope (GHO-34).
Content variant amendment
Important
Maintainer decision recorded 2026-12-01; spec amendment approved by @zprue743 on 2026-12-03. Themed GhostCollapsibleContent and GhostTabsContent take the same variant prop with the same values. This section records it for GhostCollapsibleContent; the tabs spec carries the matching amendment.
Why a variant
The themed panel draws a hairline border (open at the top, under its trigger), rounded lower corners, and inset padding. Placed inside another framed surface, such as a GhostCard or a code block, the panel draws a second border and inset padding inside the first. There is no supported way to turn that frame off.
Public API
Themed GhostCollapsibleContent in @ghostvue/themes only:
| Prop | Type | Default | Contract |
|---|---|---|---|
variant | 'framed' | 'plain' | 'framed' | framed is today's panel. plain removes the panel's border, corner radius, background and padding. |
- The union is exported as
GhostCollapsibleContentVariant, followingGhostInlineAlertVariantandGhostBadgeVariant. - The wrapper renders
data-variant="plain"on the panel and omitsdata-variantforframed, asGhostInlineAlertandGhostBadgeomit their default. The wrapper consumesvariant, so it never reaches the DOM as avariantattribute. data-variant="plain"on theghost-collapsible-contentpanel is the styling hook, under the same.ghost-theme,.ghost-themed-scope, or[data-themed]scopes as the framed recipe.- Headless
@ghostvue/vuedoes not change: no prop, type, or manifest change.GhostCollapsibleandGhostCollapsibleTriggertake novariant. Accordion content is out of scope.
Styling contract
- Removed by
plain: border, border radius, background, and padding on the panel, including the inner animation shell's padding. - Kept: text color and type,
data-state, thegrid-template-rowsandblock-sizeheight transitions, the deferredhiddenon close,disableAnimation, andprefers-reduced-motionhandling. The trigger keeps its own frame. - Tokens only. The plain rules reset properties to
0ortransparentand add no literal sizes or colors.
Accessibility and motion
Roles, names, states, keyboard, and focus order do not change. The plain panel opens and closes with the same transition and hidden timing as the framed one. Because it has no inset padding, it clips with overflow: clip and an overflow-clip-margin of the focus ring width plus offset, so a focus ring on a control at the panel edge stays visible where the engine supports overflow-clip-margin; elsewhere it clips at the edge.
Implementation acceptance cases
- Wrapper (integration). Omitting
variantandvariant="framed"render nodata-variant;variant="plain"rendersdata-variant="plain"; novariantattribute reaches the DOM. - Computed styles (browser). In a themed host, a plain open panel has zero border width, zero radius, a transparent background, and zero padding on the panel and its inner shell; a framed panel keeps its border and padding. With motion allowed, closing a plain panel still defers
hiddenuntil the transition ends. - Example and baseline.
collapsible/build-outputshows the plain panel inside aGhostCardand has visual baselines in light and dark. - Manifests and API tables. The themed manifest
packages/themes/manifests/ghost-collapsible-content.manifest.jsonrecords the prop, andpnpm docs:api:writeupdates the table ondocs/components/collapsible.md.
Compatibility
Additive. The default stays framed, so existing panels render as before. A variant attribute passed to the themed panel today falls through to the DOM and has no effect; after the change it is a typed prop. Minor Changeset for @ghostvue/themes.