Skip to content

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 variant prop on the themed GhostCollapsibleContent is 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 GhostAccordion built on GhostCollapsible.
  • 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-state and prefers-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 via default.css)

Props and configuration ​

GhostCollapsible (root) ​

PropTypeDefaultContract
openboolean | undefinedundefinedControlled open state. Omit for uncontrolled mode.
defaultOpenbooleanfalseInitial open state in uncontrolled mode.
disabledbooleanfalseWhen true, the trigger cannot toggle open state (root-level disable).

GhostCollapsibleTrigger ​

PropTypeDefaultContract
asGhostCollapsibleTriggerElement (Component | string)'button'Element tag or component (for example GhostButton).
disabledbooleanfalsePrevents toggling when true or when the root is disabled. Uses native disabled on <button> and aria-disabled="true" otherwise.

GhostCollapsibleContent ​

PropTypeDefaultContract
asGhostCollapsibleContentElement (Component | string)'div'Element tag or component for the panel.
disableAnimationbooleanfalseWhen 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 open is undefined (omitted), internal state starts at defaultOpen and updates on user toggles while still emitting update:open.
  • When open is boolean, update:open is emitted and the consumer owns the state update.

Events, callbacks, slots, and exposed methods ​

  • GhostCollapsible emits update:open with [open: boolean].
  • GhostCollapsible default slot receives { open: boolean, toggle: () => void }.
  • GhostCollapsibleTrigger and GhostCollapsibleContent expose { element: HTMLElement | null, focus(options?: FocusOptions): void, blur(): void }.

State model ​

  • Two binary states: 'closed' and 'open'.
  • GhostCollapsibleContent stays mounted in document order. When closed it uses the native hidden attribute (not v-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 when disableAnimation is true.

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 ​

  • GhostCollapsibleTrigger renders type="button" (when as="button"), id (from useGhostId, overridable by consumer id), aria-expanded="true" | "false", aria-controls="<contentId>", data-part="trigger", and data-state="open" | "closed". No aria-haspopup.
  • GhostCollapsibleContent renders id (matching aria-controls), hidden when closed, data-part="content", data-state="open" | "closed", and aria-labelledby="<triggerId>" by default unless the consumer provides aria-label or aria-labelledby.

Keyboard interaction ​

  • Trigger (button host): native Enter and Space toggle (no extra handler required on <button>).
  • Trigger (non-button host with role="button"): Enter and Space toggle 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 hidden and hidden from sighted users via display: none from the user agent or theme CSS.

Rendering and customization ​

  • Headless parts use classes ghost-collapsible-trigger and ghost-collapsible-content for theme recipes.
  • Theme CSS may animate open/close using data-state and semantic --ghost-motion-* tokens, gated with @media (prefers-reduced-motion: reduce).

Environment behavior ​

SSR and hydration ​

  • Deterministic id values from useGhostId populate aria-controls on the server.
  • Closed collapsibles render the content node with hidden in SSR HTML.
  • No window / document access 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 hidden and ARIA state.

Composition ​

  • Reuses useControllableState, useGhostId, and the as + inheritAttrs: false attribute-splitting pattern from GhostPopover / GhostDialog triggers.

Test plan ​

  • Vue: uncontrolled and controlled open, disabled on root and trigger, aria-expanded / aria-controls / hidden, SSR render, cleanup on unmount, exposed element / 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 playground CollapsibleReference with 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:

PropTypeDefaultContract
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, following GhostInlineAlertVariant and GhostBadgeVariant.
  • The wrapper renders data-variant="plain" on the panel and omits data-variant for framed, as GhostInlineAlert and GhostBadge omit their default. The wrapper consumes variant, so it never reaches the DOM as a variant attribute.
  • data-variant="plain" on the ghost-collapsible-content panel is the styling hook, under the same .ghost-theme, .ghost-themed-scope, or [data-themed] scopes as the framed recipe.
  • Headless @ghostvue/vue does not change: no prop, type, or manifest change. GhostCollapsible and GhostCollapsibleTrigger take no variant. 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, the grid-template-rows and block-size height transitions, the deferred hidden on close, disableAnimation, and prefers-reduced-motion handling. The trigger keeps its own frame.
  • Tokens only. The plain rules reset properties to 0 or transparent and 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 ​

  1. Wrapper (integration). Omitting variant and variant="framed" render no data-variant; variant="plain" renders data-variant="plain"; no variant attribute reaches the DOM.
  2. 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 hidden until the transition ends.
  3. Example and baseline. collapsible/build-output shows the plain panel inside a GhostCard and has visual baselines in light and dark.
  4. Manifests and API tables. The themed manifest packages/themes/manifests/ghost-collapsible-content.manifest.json records the prop, and pnpm docs:api:write updates the table on docs/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.