Expandable Card

Animated

A card that expands into its own detail view.

Source
$npx @dinachi/cli@latest add expandable-card
fullscreen
showClose
backdropClassName

Usage

import {
  ExpandableCard,
  ExpandableCardBody,
  ExpandableCardPanel,
  ExpandableCardShared,
  ExpandableCardTrigger,
} from "@/components/ui/expandable-card"

export function Story() {
  return (
    <ExpandableCard>
      <ExpandableCardTrigger>
        <ExpandableCardShared part="art" className="h-24 bg-muted" />
        <ExpandableCardShared part="title" className="p-4 text-sm font-medium">
          Shared layout
        </ExpandableCardShared>
      </ExpandableCardTrigger>

      <ExpandableCardPanel title="Shared layout">
        <ExpandableCardShared part="art" className="h-40 bg-muted" />
        <ExpandableCardShared part="title" className="px-5 pt-4 text-lg font-medium">
          Shared layout
        </ExpandableCardShared>
        <ExpandableCardBody className="px-5 pb-5">
          Content that only exists in the panel.
        </ExpandableCardBody>
      </ExpandableCardPanel>
    </ExpandableCard>
  )
}

Examples

Focus lands inside, Escape closes, focus comes back.
import {
  ExpandableCard,
  ExpandableCardTrigger,
  ExpandableCardPanel,
  ExpandableCardShared,
  ExpandableCardBody,
} from '@/components/ui/expandable-card';

export function Example() {
  return (
    <ExpandableCard>
      <ExpandableCardTrigger>
        <ExpandableCardShared part="art" className="h-24 bg-muted" />
        <ExpandableCardShared part="title" className="p-4 text-sm font-medium">
          The card travels
        </ExpandableCardShared>
      </ExpandableCardTrigger>

      <ExpandableCardPanel title="The card travels">
        <ExpandableCardShared part="art" className="h-40 bg-muted" />
        <ExpandableCardShared part="title" className="px-5 pt-4 text-lg font-medium">
          The card travels
        </ExpandableCardShared>
        <ExpandableCardBody className="px-5 pb-5">
          Content that only exists in the panel arrives after the landing.
        </ExpandableCardBody>
      </ExpandableCardPanel>
    </ExpandableCard>
  );
}

Notes

Motion tier

Needs motion. add --all skips it; install with add --motion or by name.

When to use it

  • A hero item, or a short list where opening one is a deliberate choice.
  • Skip it on large grids, where the travel slows every glance.
  • If the detail view shares nothing with the card, use a Dialog.

Pairing parts

  • Use each part once per side. A part used twice on one side makes the layout engine pick one.
  • Put anything on only one side in ExpandableCardBody.
  • Ids are scoped per card, so a grid of cards works.

Controlled

Use open and onOpenChange to close the panel from your own control. With showClose={false}, your control must set open back to false.

Full screen

  • Centred: sized by content, never scrolls; rounded, bordered and shadowed.
  • fullscreen: fills the screen, content scrolls inside, no radius, border or shadow.
  • The close button stays fixed outside the scroller.

Behaviour

  • The travel is a 420ms spring; the backdrop a 200ms fade.
  • Reduced motion cuts. An app-level MotionConfig reducedMotion is honoured.
  • The panel portals to document.body. An ancestor with a transform, filter, backdrop-filter, perspective or paint containment breaks position: fixed; pass container to portal elsewhere.

API

openboolean
Controlled open state.
defaultOpenboolean = false
Starting open state when uncontrolled.
onOpenChange
agent
(open, details) => void
Runs before open or close, for people and agents. details.cancel() refuses it.

Agent

Inside an AgentProvider, it appears in agent.snapshot() as disclosure.

Reads

label

The card's text while closed. The panel's title while open.

open

Whether the panel is showing.

Actions

open()

While closed. Opens the panel like a click on the card.

close()

While open. Closes the panel.

An agent's open or close runs through onOpenChange with details.reason set to imperative-action. isAgentChange(details) is true for it; details.cancel() keeps the card as it was and tells the agent the app refused.

await agent.act({
  steps: [{ ref: "The card travels", action: "open" }],
})

Accessibility

  • The panel is a modal dialog with aria-modal, named by its title.
  • Focus moves to the panel's first control on open and back to the card on close.
  • The card is inert while open.
  • Page scroll is locked, with scrollbar compensation so layout does not shift.
  • The trigger is a button with aria-haspopup="dialog" and aria-expanded.