Components

Expandable Card

Expandable cards for React and Tailwind CSS: click a card and it grows into a large overlay panel, with the image, title and summary morphing into place through shared Motion layout animations. Built on Radix Dialog, so focus trapping, Escape, outside click and focus return work out of the box.

  • Shared layoutId morph
  • Radix Dialog
  • Grid or list
  • Data-driven
  • prefers-reduced-motion

Installation

$ npx shadcn@latest add https://duskui.com/r/expandable-card.json

Usage

projects.tsx
import { ExpandableCard } from "@/components/dusk/expandable-card/expandable-card"

const items = [
  {
    id: "atlas",
    title: "Atlas",
    subtitle: "Case study",
    description: "A design system for a fleet of internal tools.",
    media: <img src="/atlas.jpg" alt="" />,
    content: <p>Longer story shown only in the expanded panel.</p>,
  },
]

export function Projects() {
  return <ExpandableCard items={items} />
}

Examples

List layout

layout="list" shows compact rows with a thumbnail that grows into the panel's full-width artwork. Good for playlists, changelogs and team pages.

API Reference

Each item is { id, title, subtitle?, description, media?, content?, action? }. The root also accepts any <div> attribute.

PropTypeDefaultDescription
itemsExpandableCardItem[]—Cards to render. media, title, subtitle and description are shared between the card and the panel.
layout"grid" | "list""grid"Media-first tiles in a responsive grid, or compact rows.
onActiveChange(id: string | null) => void—Called with the expanded item's id, or null when the panel closes.
cardClassNamestring—Classes for each card.
panelClassNamestring—Classes for the expanded panel, e.g. a wider max-w.
item.contentReactNode—Extra content that fades in only in the panel.
item.actionReactNode—A button or link at the bottom of the panel.

Accessibility

  • Each card is a real <button> with aria-haspopup="dialog".
  • The panel is a Radix Dialog: focus moves inside and is trapped, the page behind is inert, and the title and summary are wired to aria-labelledby and aria-describedby.
  • Escape, the close button and clicking the backdrop all close it, and focus returns to the exact card that opened it.
  • With prefers-reduced-motion the layout morph is turned off and the panel simply fades in and out.
  • Give images in media an alt (or alt="" when the title already describes them).