Card that morphs into a dialog on one shared spring, centered, immersive or as a side panel, and a bottom sheet on phones.
Click meTap me
morphing-dialog, lively
Use it when a card is a preview of something the user will want to look at in detail: a product, a photo, a deployment, a profile. Because the card itself becomes the dialog, people keep their place: the image, title and subtitle travel to where they belong in the dialog, and closing plays the morph in reverse back into the card.
The motion follows the MotionKit grammar in three beats. Pressing the card charges it (it sinks a little under the finger). The action is the morph: the card becomes the dialog on one shared spring whose speed comes from the temperament but which never bounces, because on a size change of hundreds of pixels even a light overshoot pushes the panel past the screen edge. The settle belongs to the small parts: the dialog's own content rises in after the shared parts and the close button pops in with the temperament's bounce. Closing reverses it: the dialog's own parts sink and fade out over the first part of the way back, then the card lands where it was.
pnpm dlx shadcn@latest add @motionkit-pro/morphing-dialognpx shadcn@latest add @motionkit-pro/morphing-dialogyarn dlx shadcn@latest add @motionkit-pro/morphing-dialogbunx --bun shadcn@latest add @motionkit-pro/morphing-dialogRequires a Pro license and the @motionkit-pro registry with your token. See Installation.
import { MorphingDialog } from "@/components/ui/morphing-dialog"
export function ProductCard() {
return (
<MorphingDialog.Root>
<MorphingDialog.Trigger className="w-64">
<MorphingDialog.Image src="/lamp.jpg" alt="" className="aspect-[4/3]" />
<span className="p-4">
<MorphingDialog.Title className="text-sm">Lumen desk lamp</MorphingDialog.Title>
<MorphingDialog.Subtitle className="text-xs">€189</MorphingDialog.Subtitle>
</span>
</MorphingDialog.Trigger>
<MorphingDialog.Content>
<MorphingDialog.Image src="/lamp.jpg" alt="Brass desk lamp" className="aspect-[4/3]" />
<div className="px-6 pt-5">
<MorphingDialog.Title className="text-xl">Lumen desk lamp</MorphingDialog.Title>
<MorphingDialog.Subtitle className="text-sm">€189</MorphingDialog.Subtitle>
</div>
<MorphingDialog.Description className="px-6 pt-3 pb-6 text-sm">
A brass-weighted lamp with a dimmable warm LED.
</MorphingDialog.Description>
<MorphingDialog.Close />
</MorphingDialog.Content>
</MorphingDialog.Root>
)
}| Part | Renders | Notes |
|---|---|---|
Root | Radix Dialog Root | preset, temperament, open / defaultOpen / onOpenChange |
Trigger | <button>, the card | Morphs into Content. Keep its content phrasing (spans, images). |
Content | Radix Dialog Content | Focus trap, Escape, outside click, scroll lock. Scrolls when tall. |
Image | <img> shared by both | Use the same aspect ratio in card and dialog. |
Media | <span> shared by both | Video, illustrations or generated art. Valid inside the card. |
Title | <h2> in the dialog, span in the card | Names the dialog for screen readers. |
Subtitle | <span> shared by both | Price, author, branch... |
Description | <p>, Radix Dialog Description | Short prose read after the title. Rises in after the morph. |
Body | <div>, a span in the card | Only in one of the two: lists, metadata, actions. See below. |
Close | Radix Dialog Close | Icon button, top right. Pass children to replace the icon. |
Image, Media, Title and Subtitle are matched between the card and the dialog
automatically: use each at most once in Trigger and once in Content.
Wrap everything else in Body. In the dialog it rises in after the morph (index sets the
stagger, like Description). On the card it disappears while the card is away and fades back in
once the card has landed, so a status badge or a timestamp never stretches with the morph or
crowds the returning title.
centered (default): a dialog in the middle of the screen over a blurred backdrop.immersive: fills the screen, for galleries, articles and media.side-panel: a tall panel on the right, for details next to a list or table.Below 640px wide centered and side-panel become a bottom sheet with rounded top corners;
immersive stays full screen.
Prop
Type
Also accepts all props of Omit<
ComponentProps<typeof DialogPrimitive.Root>,
"modal"
>.
Prop
Type
Also accepts all props of Omit<
ComponentProps<typeof motion.button>,
"children"
>.
Prop
Type
Also accepts all props of Omit<
ComponentProps<typeof motion.div>,
"children"
>.
Prop
Type
Also accepts all props of ComponentProps<typeof motion.p>.
Prop
Type
Click meTap me
morphing-dialog, lively
Click meTap me
morphing-dialog, lively
role="dialog" with aria-modal, named by Title and described by
Description. When it opens, focus moves to the dialog itself (so its name is read first, not
its last button) and stays trapped inside; the rest of the page is hidden from assistive tech.<button> with aria-expanded and aria-haspopup="dialog".aria-label on Trigger (see the gallery example).transform only, correcting corner radii and children. Shared text only travels and
scales uniformly from one font size to the other, so letters keep their shape in every frame.overflow: hidden, a scroll container or
a neighboring card can't clip or cover it, and the card reappears (with its focus ring, if
focused) only once the copy has landed on it. A card inside a .dark section of a light page
keeps that scheme in the dialog and its copy.getBoundingClientRect per frame, only
while the morph runs.document.body, or into container (or MotionKitProvider's
portalContainer) to stay inside a themed section. Keep transforms, filters and contain off
that element's ancestors so the fixed overlay still covers the viewport.aria-hidden, on top of Motion and Radix Dialog and Focus Scope,
which shadcn projects already ship.With reduced motion (the OS setting, or MotionKitProvider reducedMotion="always") the card does
not morph: the dialog fades in and out in place in 200ms and its content appears without rising
or staggering.
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Not measured yet · budget 15.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, @radix-ui/react-dialog, @radix-ui/react-focus-scope, motion.
click
No morph: the dialog fades in and out in place in 200ms, and its content appears without rising or staggering.
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)