Skip to content

feat(Collapsible): add XDSCollapsible primitive and XDSCollapsibleGroup - #263

Merged
cixzhang merged 9 commits into
mainfrom
navi/feat/collapsible-accordion
Feb 22, 2026
Merged

cixzhang merged 9 commits into
mainfrom
navi/feat/collapsible-accordion

Conversation

@cixzhang

@cixzhang cixzhang commented Feb 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds XDSCollapsible — a standalone primitive that makes any content collapsible — and XDSCollapsibleGroup for coordinating multiple collapsibles (accordion pattern).

API

// Standalone — inside a card
<XDSCard>
  <XDSCollapsible trigger="Details">
    <p>Collapsible content</p>
  </XDSCollapsible>
</XDSCard>

// Standalone — works anywhere, no card needed
<XDSCollapsible trigger="Show more" initialIsOpen={false}>
  <p>Expandable content</p>
</XDSCollapsible>

// Accordion pattern — single open at a time
<XDSCollapsibleGroup type="single" defaultValue="general">
  <XDSVStack gap="space2">
    <XDSCard>
      <XDSCollapsible trigger="General" value="general">
        <GeneralSettings />
      </XDSCollapsible>
    </XDSCard>
    <XDSCard>
      <XDSCollapsible trigger="Advanced" value="advanced">
        <AdvancedSettings />
      </XDSCollapsible>
    </XDSCard>
  </XDSVStack>
</XDSCollapsibleGroup>

Design decisions

  • Composition over configuration. Collapsible is a primitive you compose inside containers (Card, Section, etc.), not a prop on those containers. This keeps Card as a pure visual container and makes collapsible behavior reusable anywhere.
  • trigger prop, not a sub-component. Prevents Radix-style hallucinations (AccordionItem, CollapsibleTrigger, etc.). Vibe tested at 5/5 discoverability with zero hallucinations.
  • XDSCollapsibleGroup renders no DOM. Pure context provider for coordination. Works with any layout (VStack, List, etc.).
  • useXDSCollapsible hook extracted for reuse — powers both standalone and group modes.

What's included

  • XDSCollapsible component — trigger, chevron indicator, aria-expanded, keyboard activation
  • XDSCollapsibleGroup — single/multiple mode, controlled/uncontrolled, defaultValue
  • useXDSCollapsible hook — reusable state management
  • 18 tests covering standalone, group, controlled, keyboard, accessibility
  • 6 stories: single mode, multiple mode, controlled, standalone, without card, FAQ page
  • Updated docs for CollapsibleGroup and Card READMEs

Closes #187, closes #188


Crafted with care by Navi

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Feb 21, 2026
@github-actions

github-actions Bot commented Feb 21, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

New Components

CollapsibleGroup
Metric Value
Bundle Size (ESM) 239B
Bundle Size (CJS) 393B
Lines of Code 239
Source Files 5
Complexity High (18)
Exports XDSCollapsible, XDSCollapsibleGroup, useXDSCollapsible
Props Count 7
Has Tests Yes
Has Stories No

Modified Components

Card · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 169B N/A
Lines of Code N/A 114 -
Complexity N/A Medium (14) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 7.1KB 11.5KB 1.9KB

Accessibility Audit

Status: No accessibility violations detected.

Component Previews

Includes interactive hover previews as animated GIFs.

XDSCard

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · layout-xdscard--default

With Simple Content

Screenshot:

With Simple Content

View in Storybook · layout-xdscard--with-simple-content

With Inner Layout

Screenshot:

With Inner Layout

View in Storybook · layout-xdscard--with-inner-layout

Sizes

Screenshot:

Sizes

View in Storybook · layout-xdscard--sizes

Fixed Height

Screenshot:

Fixed Height

View in Storybook · layout-xdscard--fixed-height

Nested Cards

Screenshot:

Nested Cards

View in Storybook · layout-xdscard--nested-cards

Nested Sections

Screenshot:

Nested Sections

View in Storybook · layout-xdscard--nested-sections

Single Section

Screenshot:

Single Section

View in Storybook · layout-xdscard--single-section

Mixed Content

Screenshot:

Mixed Content

View in Storybook · layout-xdscard--mixed-content

Full Bleed

Screenshot:

Full Bleed

View in Storybook · layout-xdscard--full-bleed


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang

Copy link
Copy Markdown
Contributor Author

Vibe Test Comparison: XDSAccordion vs XDSCollapsibleGroup

Ran 3 accordion/collapsible prompts against the CLI-generated skill doc to compare discoverability.

Results

Dimension XDSAccordion (before) XDSCollapsibleGroup (after)
"Collapsible" prompts 3/5 5/5
"Accordion" prompts 5/5 4/5
Sub-component hallucination risk High (AccordionItem/Trigger) Low
Context export confusion Yes (appeared as separate component) Fixed (internal only)
Description clarity "Coordination context for collapsible components" "Groups collapsible components with coordinated open/close behavior"
Overall discoverability 3.5/5 4.7/5

Key Findings

  1. +1.2 discoverability improvement. Most prompts describe behavior ("collapsible sections", "expandable cards") not pattern names ("accordion"). CollapsibleGroup matches behavioral descriptions better.

  2. Hallucination eliminated. "XDSAccordion" strongly implies Radix-style sub-components (AccordionItem, AccordionTrigger, AccordionContent). CollapsibleGroup carries no such baggage — the LLM correctly used XDSCard with isCollapsible across all prompts.

  3. Context export removal is a big win. XDSAccordionContext previously appeared in the component catalog with identical props, confusing the LLM. Now only XDSCollapsibleGroup is visible.

  4. Minor tradeoff. "Accordion-style" prompts score 4/5 instead of 5/5 — requires conceptual leap from "accordion" → "collapsible group." Acceptable since most real prompts describe behavior.

  5. CLI scanner fixed. *Context.tsx files are now excluded from component discovery, preventing internal implementation details from polluting the catalog.

Methodology

  • Skill doc generated from CLI (xds component --brief-all + xds docs)
  • LLM constrained to ONLY use information in the skill doc
  • No prior knowledge of XDS API
  • Self-evaluated on discoverability, correctness, and hallucination risk

Comment thread packages/core/src/Card/XDSCard.tsx Resolved
Comment thread packages/core/src/Card/XDSCard.tsx Resolved
Comment thread packages/core/src/Card/XDSCard.tsx Resolved
cixzhang added a commit that referenced this pull request Feb 22, 2026
…, fix card layout

Address three architectural review comments from PR #263:

1. ChevronIcon → icon registry: Remove inline SVG ChevronIcon function,
   use useXDSIcon('chevronDown') from the icon registry instead. The
   chevronDown icon already exists in defaultIcons.

2. Extract useCollapsible hook: Move collapsible state management logic
   (config parsing, CollapsibleGroup context check, internal state,
   toggle handler) from XDSCard into a reusable useCollapsible hook in
   packages/core/src/CollapsibleGroup/. This enables other components
   (Section, Banner, etc.) to reuse the same collapsible behavior.

3. Fix card title layout: Move title rendering outside the cardInner
   wrapper so it doesn't conflict with Layout's slot system. The title
   now renders as a fixed header area with its own padding, while
   cardInner handles only the content area. When no title is provided,
   the card renders exactly as before.

Co-authored-by: Navi <[email protected]>
cixzhang and others added 6 commits February 22, 2026 15:34
…dination context

Add collapsible behavior to XDSCard via isCollapsible prop:
- isCollapsible={true} for self-managed state (default open)
- isCollapsible={{ initialIsOpen: false }} to start collapsed
- isCollapsible={{ isOpen, onOpenChange }} for controlled mode
- title prop renders a header that becomes the click trigger
- Chevron indicator, aria-expanded, keyboard support

Add XDSAccordion coordination context:
- Renders no wrapper DOM, just context provider
- type="single" (default): only one item open at a time
- type="multiple": any number of items open
- Supports controlled (value/onValueChange) and uncontrolled (defaultValue)
- Cards with value prop inside accordion defer to accordion state

Add vibe test prompts for collapsible/accordion patterns.

Closes #187, closes #188

Co-authored-by: Navi <[email protected]>
… exports

- Rename XDSAccordion → XDSCollapsibleGroup across all files
- Rename AccordionContext → CollapsibleGroupContext (internal only)
- Remove context from public exports (was confusingly listed as separate component)
- Update XDSCard to use CollapsibleGroupContext
- Add CollapsibleGroup to package.json exports and CLI category mapping
- Exclude *Context.tsx files from CLI component discovery
- Update storybook stories, READMEs, and all documentation
- Add vibe test results showing improved discoverability (3.5 → 4.7/5)

Co-authored-by: Navi <[email protected]>
…, fix card layout

Address three architectural review comments from PR #263:

1. ChevronIcon → icon registry: Remove inline SVG ChevronIcon function,
   use useXDSIcon('chevronDown') from the icon registry instead. The
   chevronDown icon already exists in defaultIcons.

2. Extract useCollapsible hook: Move collapsible state management logic
   (config parsing, CollapsibleGroup context check, internal state,
   toggle handler) from XDSCard into a reusable useCollapsible hook in
   packages/core/src/CollapsibleGroup/. This enables other components
   (Section, Banner, etc.) to reuse the same collapsible behavior.

3. Fix card title layout: Move title rendering outside the cardInner
   wrapper so it doesn't conflict with Layout's slot system. The title
   now renders as a fixed header area with its own padding, while
   cardInner handles only the content area. When no title is provided,
   the card renders exactly as before.

Co-authored-by: Navi <[email protected]>
All public hooks use the `useXDS` prefix per XDS naming conventions.

Renamed:
- useCollapsible → useXDSCollapsible
- UseCollapsibleOptions → UseXDSCollapsibleOptions
- UseCollapsibleReturn → UseXDSCollapsibleReturn
- useCollapsible.ts → useXDSCollapsible.ts

Co-authored-by: Navi <[email protected]>
…psible from Card

XDSCollapsible is now a standalone primitive that composes inside any
container (Card, Section, or standalone). Card no longer has title,
isCollapsible, or value props — it's back to being a pure visual container.

- Add XDSCollapsible component with trigger prop, chevron, a11y
- XDSCollapsibleGroup coordinates XDSCollapsible instances (unchanged API)
- useXDSCollapsible hook powers both standalone and group modes
- Updated stories to show composition pattern (Collapsible inside Card)
- All tests rewritten for the new API

Co-authored-by: Navi <[email protected]>
@cixzhang cixzhang changed the title feat(Accordion): add isCollapsible prop on Card and XDSAccordion coordination context feat(Collapsible): add XDSCollapsible primitive and XDSCollapsibleGroup Feb 22, 2026
@cixzhang
cixzhang merged commit e4c2ca9 into main Feb 22, 2026
9 checks passed
@cixzhang
cixzhang deleted the navi/feat/collapsible-accordion branch February 22, 2026 19:19
cixzhang added a commit that referenced this pull request Apr 26, 2026
…up (#263)

* feat(Accordion): add isCollapsible prop on Card and XDSAccordion coordination context

Add collapsible behavior to XDSCard via isCollapsible prop:
- isCollapsible={true} for self-managed state (default open)
- isCollapsible={{ initialIsOpen: false }} to start collapsed
- isCollapsible={{ isOpen, onOpenChange }} for controlled mode
- title prop renders a header that becomes the click trigger
- Chevron indicator, aria-expanded, keyboard support

Add XDSAccordion coordination context:
- Renders no wrapper DOM, just context provider
- type="single" (default): only one item open at a time
- type="multiple": any number of items open
- Supports controlled (value/onValueChange) and uncontrolled (defaultValue)
- Cards with value prop inside accordion defer to accordion state

Add vibe test prompts for collapsible/accordion patterns.

Closes #187, closes #188

Co-authored-by: Navi <[email protected]>

* refactor(Accordion): rename to XDSCollapsibleGroup, hide context from exports

- Rename XDSAccordion → XDSCollapsibleGroup across all files
- Rename AccordionContext → CollapsibleGroupContext (internal only)
- Remove context from public exports (was confusingly listed as separate component)
- Update XDSCard to use CollapsibleGroupContext
- Add CollapsibleGroup to package.json exports and CLI category mapping
- Exclude *Context.tsx files from CLI component discovery
- Update storybook stories, READMEs, and all documentation
- Add vibe test results showing improved discoverability (3.5 → 4.7/5)

Co-authored-by: Navi <[email protected]>

* docs(CollapsibleGroup): add XDSVStack gap between cards in examples

Co-authored-by: Navi <[email protected]>

* fix: correct gap values from sm/md/lg to space2/space4 in examples

Co-authored-by: Navi <[email protected]>

* refactor(Collapsible): extract useCollapsible hook, use icon registry, fix card layout

Address three architectural review comments from PR #263:

1. ChevronIcon → icon registry: Remove inline SVG ChevronIcon function,
   use useXDSIcon('chevronDown') from the icon registry instead. The
   chevronDown icon already exists in defaultIcons.

2. Extract useCollapsible hook: Move collapsible state management logic
   (config parsing, CollapsibleGroup context check, internal state,
   toggle handler) from XDSCard into a reusable useCollapsible hook in
   packages/core/src/CollapsibleGroup/. This enables other components
   (Section, Banner, etc.) to reuse the same collapsible behavior.

3. Fix card title layout: Move title rendering outside the cardInner
   wrapper so it doesn't conflict with Layout's slot system. The title
   now renders as a fixed header area with its own padding, while
   cardInner handles only the content area. When no title is provided,
   the card renders exactly as before.

Co-authored-by: Navi <[email protected]>

* refactor(Collapsible): rename useCollapsible to useXDSCollapsible

All public hooks use the `useXDS` prefix per XDS naming conventions.

Renamed:
- useCollapsible → useXDSCollapsible
- UseCollapsibleOptions → UseXDSCollapsibleOptions
- UseCollapsibleReturn → UseXDSCollapsibleReturn
- useCollapsible.ts → useXDSCollapsible.ts

Co-authored-by: Navi <[email protected]>

* refactor(Collapsible): extract XDSCollapsible primitive, remove collapsible from Card

XDSCollapsible is now a standalone primitive that composes inside any
container (Card, Section, or standalone). Card no longer has title,
isCollapsible, or value props — it's back to being a pure visual container.

- Add XDSCollapsible component with trigger prop, chevron, a11y
- XDSCollapsibleGroup coordinates XDSCollapsible instances (unchanged API)
- useXDSCollapsible hook powers both standalone and group modes
- Updated stories to show composition pattern (Collapsible inside Card)
- All tests rewritten for the new API

Co-authored-by: Navi <[email protected]>

* docs(Collapsible): rename README title from CollapsibleGroup to Collapsible

Co-authored-by: Navi <[email protected]>

* docs(Collapsible): rename storybook title and file from CollapsibleGroup to Collapsible

Co-authored-by: Navi <[email protected]>

---------

Co-authored-by: Navi <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
…up (#263)

* feat(Accordion): add isCollapsible prop on Card and XDSAccordion coordination context

Add collapsible behavior to XDSCard via isCollapsible prop:
- isCollapsible={true} for self-managed state (default open)
- isCollapsible={{ initialIsOpen: false }} to start collapsed
- isCollapsible={{ isOpen, onOpenChange }} for controlled mode
- title prop renders a header that becomes the click trigger
- Chevron indicator, aria-expanded, keyboard support

Add XDSAccordion coordination context:
- Renders no wrapper DOM, just context provider
- type="single" (default): only one item open at a time
- type="multiple": any number of items open
- Supports controlled (value/onValueChange) and uncontrolled (defaultValue)
- Cards with value prop inside accordion defer to accordion state

Add vibe test prompts for collapsible/accordion patterns.

Closes #187, closes #188


* refactor(Accordion): rename to XDSCollapsibleGroup, hide context from exports

- Rename XDSAccordion → XDSCollapsibleGroup across all files
- Rename AccordionContext → CollapsibleGroupContext (internal only)
- Remove context from public exports (was confusingly listed as separate component)
- Update XDSCard to use CollapsibleGroupContext
- Add CollapsibleGroup to package.json exports and CLI category mapping
- Exclude *Context.tsx files from CLI component discovery
- Update storybook stories, READMEs, and all documentation
- Add vibe test results showing improved discoverability (3.5 → 4.7/5)


* docs(CollapsibleGroup): add XDSVStack gap between cards in examples


* fix: correct gap values from sm/md/lg to space2/space4 in examples


* refactor(Collapsible): extract useCollapsible hook, use icon registry, fix card layout

Address three architectural review comments from PR #263:

1. ChevronIcon → icon registry: Remove inline SVG ChevronIcon function,
   use useXDSIcon('chevronDown') from the icon registry instead. The
   chevronDown icon already exists in defaultIcons.

2. Extract useCollapsible hook: Move collapsible state management logic
   (config parsing, CollapsibleGroup context check, internal state,
   toggle handler) from XDSCard into a reusable useCollapsible hook in
   packages/core/src/CollapsibleGroup/. This enables other components
   (Section, Banner, etc.) to reuse the same collapsible behavior.

3. Fix card title layout: Move title rendering outside the cardInner
   wrapper so it doesn't conflict with Layout's slot system. The title
   now renders as a fixed header area with its own padding, while
   cardInner handles only the content area. When no title is provided,
   the card renders exactly as before.


* refactor(Collapsible): rename useCollapsible to useXDSCollapsible

All public hooks use the `useXDS` prefix per XDS naming conventions.

Renamed:
- useCollapsible → useXDSCollapsible
- UseCollapsibleOptions → UseXDSCollapsibleOptions
- UseCollapsibleReturn → UseXDSCollapsibleReturn
- useCollapsible.ts → useXDSCollapsible.ts


* refactor(Collapsible): extract XDSCollapsible primitive, remove collapsible from Card

XDSCollapsible is now a standalone primitive that composes inside any
container (Card, Section, or standalone). Card no longer has title,
isCollapsible, or value props — it's back to being a pure visual container.

- Add XDSCollapsible component with trigger prop, chevron, a11y
- XDSCollapsibleGroup coordinates XDSCollapsible instances (unchanged API)
- useXDSCollapsible hook powers both standalone and group modes
- Updated stories to show composition pattern (Collapsible inside Card)
- All tests rewritten for the new API


* docs(Collapsible): rename README title from CollapsibleGroup to Collapsible


* docs(Collapsible): rename storybook title and file from CollapsibleGroup to Collapsible


---------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XDSAccordion useXDSCollapsible hook + collapsible prop pattern

1 participant