Skip to content

useXDSCollapsible hook + collapsible prop pattern #187

Closed

Description

@cixzhang

Spec (revised 2026-02-21)

Add isCollapsible prop to components with a header/content split (Card, Section, Banner, PageNavSection, ListItem, etc.).

Approach

isCollapsible is a prop on the component, not a standalone hook. The component manages its own collapse state internally. When inside an XDSAccordion (#188), the component defers to the accordion for coordination.

API

type CollapsibleConfig = {
  initialIsOpen?: boolean;  // default true
  isOpen?: boolean;         // controlled
  onOpenChange?: (isOpen: boolean) => void;
};

// The prop accepts boolean or config
isCollapsible?: boolean | CollapsibleConfig;

// Used by Accordion for identification
value?: string;

Usage

// Simple — just a boolean, component manages everything
<XDSCard title="Details" isCollapsible>
  <Content />
</XDSCard>

// Uncontrolled with config
<XDSCard title="Details" isCollapsible={{ initialIsOpen: false }}>
  <Content />
</XDSCard>

// Controlled
<XDSCard title="Details" isCollapsible={{ isOpen, onOpenChange: setIsOpen }}>
  <Content />
</XDSCard>

// Inside an Accordion — defers to accordion context
<XDSAccordion type="single" defaultValue="general">
  <XDSVStack gap="space2">
    <XDSCard title="General" value="general" isCollapsible>...</XDSCard>
    <XDSCard title="Advanced" value="advanced" isCollapsible>...</XDSCard>
  </XDSVStack>
</XDSAccordion>

How components implement it

Each component that supports isCollapsible:

  1. Accepts isCollapsible prop (boolean or config) and value prop (string, for Accordion)
  2. Checks for Accordion context — if present AND value is set, defers to accordion
  3. Otherwise manages its own internal open/close state
  4. Renders a trigger (the header/title area) and a collapsible content area
  5. Trigger gets aria-expanded, chevron indicator
  6. Content area collapses/expands (snap for now, ViewTransitions later)

Key decisions

Decision Choice Rationale
Prop, not hook isCollapsible on components Hooks break with dynamic lists. Prop is simpler.
Boolean or config true for simple, object for controlled Layered complexity.
No useXDSCollapsible hook Removed Hook was the wrong primitive.
Accordion integration Via context + value prop Component checks for Accordion context. If present, defers. If not, self-manages.
Component manages state Yes isCollapsible={true} just works — no external state needed.

v1 scope

Start with XDSCard, then extend to Section, Banner, PageNavSection, ListItem.

Animation

ViewTransitions for collapse/expand (deferred — snap for now).

Activity

  1. added
    enhancement
    on Feb 19, 2026
  2. changed the title [-]XDSCollapsible[/-] [+]useXDSCollapsible hook + collapsible prop pattern[/+] on Feb 19, 2026
  3. added a commit that references this issue on Feb 20, 2026
    bd73821
  4. cixzhang commented on Feb 22, 2026

    @cixzhang
    ContributorAuthor

    Update: isCollapsible implemented on XDSCard

    PR #263 adds isCollapsible prop to XDSCard with the layered approach:

    • isCollapsible={true} — self-managed, default open
    • isCollapsible={{ initialIsOpen: false }} — starts collapsed
    • isCollapsible={{ isOpen, onOpenChange }} — controlled externally
    • Inside XDSCollapsibleGroup with a value prop — defers to group coordination

    Vibe test validated

    Tested discoverability with CLI-generated skill docs. LLMs correctly discover isCollapsible on XDSCard and pair it with XDSCollapsibleGroup (renamed from XDSAccordion for better discoverability — see #188 for comparison data).

    Next: extend isCollapsible to XDSSection, XDSBanner, XDSPageNavSection, XDSListItem.

  5. added 3 commits that reference this issue on Feb 22, 2026
    6d35685
    afb0f94
    e4c2ca9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions