Skip to content
synccn

Expandable Card

New

A card that grows out of the grid into a full panel and shrinks back on close. FLIP animation, no libraries.

Installation

$ pnpm dlx shadcn@latest add @synccn/expandable-card

First time in this project? Connect synccn with one command.

Usage

import { ExpandableCard } from "@/components/ui/expandable-card";<ExpandableCard title="Saved views" preview={<Card />}>Details…</ExpandableCard>

API reference

Generated from the component's TypeScript types, so it always matches the code.

ExpandableCard

A card that grows out of its spot in the grid into a full panel, and shrinks back on close (a FLIP animation, no libraries). Escape, the close button or the backdrop close it.

  • previewrequired
    React.ReactNode

    The card as it sits in the grid.

  • titlerequired
    string

    Heading of the open card, also its accessible name.

  • children
    React.ReactNode

    Extra content shown only when open.

  • className
    string

    Extra classes for the card in the grid.

  • panelClassName
    string

    Extra classes for the open panel.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/hooksuseEscape (closes on Escape), useFocusTrap (keeps focus inside while open), useIsClient (renders portals only in the browser), useLockScroll (locks page scroll while open)
  • lib/utilscn (merges class names)

npm packages

Keyboard

  • EnterorSpaceOpen the card
  • TaborShift+TabMove focus; it stays inside while open
  • EscClose

Accessibility

  • The open card is a modal dialog that traps focus and returns it to the card when closed. Reduced motion skips the animation.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: dialog
  • ARIA attributes: aria-expanded, aria-haspopup, aria-label, aria-modal
  • Keeps keyboard focus inside while open, and returns it when closed
  • Closes with Escape
  • Stops the page behind from scrolling while open
  • Respects the reduced motion setting
  • Shows a visible focus ring for keyboard users