Skip to content

Morphing Dialog for React

A morphing dialog for React where a card grows into a modal: its image, title and surface fly into place with Motion's shared layout animation.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/morphing-dialog.json
  • MorphingDialog
  • MorphingDialogClose
  • MorphingDialogMedia
  • MorphingDialogTitle
  • MorphingDialogActions
  • +8 more
  • +5 more

Open a card, then close it with Escape, the × button or a click outside: everything flies back. Keep the media's aspect ratio the same in card and dialog.

Files to copy

5 folders · 7 files · 4 packages
From theme/src/
  • components/morphing-dialog/
  • hooks/{use-controllable.ts, use-media-query.ts, use-preferences.ts}
  • motion/{presets.ts, tokens.ts}
  • lib/{cn.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/morphing-dialog.jsonRegistry item: morphing-dialog. The styles need the Tailwind v4 glass UI setup.
The examples also use
  • components/avatar/
  • components/button/
  • components/spinner/
  • components/toast/
  • hooks/{use-direction.ts, use-latest.ts, use-magnetic.ts}
  • motion/gate.ts
  • lib/{form.ts, initials.ts, state-light.tsx}
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/avatar.json https://lokendra-builds.github.io/sheenui/r/button.json https://lokendra-builds.github.io/sheenui/r/toast.json
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Compact card

No picture: just the surface and the text morph. The dialog takes any content, and its glass level and radius are props. Buttons go in MorphingDialogActions, where each one (glass included) fades itself in.

MorphingDialog props

PropTypeDefaultDescription
children (required)ReactNodeNoneThe trigger card and the dialog content.
openbooleanNoneWhether the dialog is open (controlled); pair it with onOpenChange.
defaultOpenbooleanfalseOpen on first render (uncontrolled).
onOpenChange((open: boolean) => void)NoneCalled when the dialog opens or closes.

MorphingDialogTrigger props

PropTypeDefaultDescription
childrenReactNodeNoneThe card's content: usually MorphingDialogMedia, MorphingDialogTitle and MorphingDialogSubtitle.
level2 | 1 | 32Glass level of the card: 1 = subtle, 2 = cards (default), 3 = most opaque.
tintbooleanfalseTints the card with the accent colour.
radiusnumberthe theme's --sheen-radius-lgSets the corner radius in px.
styleCSSPropertiesNoneInline styles for the card (the corner radius is added).

MorphingDialogContent props

PropTypeDefaultDescription
childrenReactNodeNoneThe dialog's content: media, title, subtitle, description and actions.
level2 | 1 | 33Sets the glass level of the dialog: 1 to 3.
radiusnumberthe theme's --sheen-radius-xlSets the corner radius in px.
showClosebooleantrueShow the × button in the top-right corner.
labelsPartial<MorphingDialogLabels>defaultMorphingDialogLabelsEvery string, for translation: { close: "Close" } (accessible name of the × button). Every other string, for translation: labels={{ close: "…" }}; omitted keys keep the English of defaultMorphingDialogLabels. Its only key is listed in the key table under the props table.
initialFocusboolean | RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | HTMLElement | null | void)the first control (the popup itself on touch)Where focus goes when it opens (Base UI): a ref, false, or a function of the interaction type.
finalFocusboolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | HTMLElement | null | void)back to the cardWhere focus goes when it closes (Base UI).
styleCSSPropertiesNoneInline styles for the dialog (the corner radius is added).
MorphingDialogLabels keys and English defaults (1)
Pass any key in labels; the rest keep the defaults of defaultMorphingDialogLabels.
KeyEnglish default
closeClose

Parts

PropTypeDefaultDescription
MorphingDialogMediaradius?: number--sheen-radius-mdThe picture that flies between card and dialog. Same aspect ratio in both.
MorphingDialogTitlechildrenNoneMoves between card and dialog; in the dialog it is the h2 that names it.
MorphingDialogSubtitlechildrenNoneA line under the title that moves too.
MorphingDialogDescriptionchildrenNoneDialog-only text that rises in after the flight; describes the dialog. Keep controls out of it.
MorphingDialogActionschildren, classNameNoneThe dialog's buttons: the row rises in and each control fades itself, so glass buttons keep their blur.
MorphingDialogCloselabels?: Partial<MorphingDialogLabels>{ close: "Close" }The × button, if you place it yourself (showClose={false}); labels.close is its accessible name.

MorphingDialogActions props

PropTypeDefaultDescription
childrenReactNodeNoneThe dialog's buttons and other controls.
classNamestringNoneAdds extra classes to the row.

MorphingDialogClose props

PropTypeDefaultDescription
labelsPartial<MorphingDialogLabels>defaultMorphingDialogLabelsEvery string, for translation: close is the button's accessible name (default "Close"). Every other string, for translation: labels={{ close: "…" }}; omitted keys keep the English of defaultMorphingDialogLabels. Its only key is listed in the key table under the props table.
classNamestringNoneAdds extra classes to the button.

MorphingDialogDescription props

PropTypeDefaultDescription
childrenReactNodeNoneHolds the description text (and non-glass figures).
classNamestringNoneAdds extra classes to the description.

MorphingDialogMedia props

PropTypeDefaultDescription
childrenReactNodeNoneThe picture: an <img>, a video poster or artwork.
radiusnumberthe theme's --sheen-radius-mdSets the corner radius in px.
classNamestringNoneExtra classes (set the aspect ratio here, the same in the card and the dialog).
styleCSSPropertiesNoneInline styles for the media box (the corner radius is added).

MorphingDialogSubtitle props

PropTypeDefaultDescription
childrenReactNodeNoneThe text to show; it moves with the card while the dialog opens and closes.
classNamestringNoneAdds extra classes to the text element.

MorphingDialogTitle props

PropTypeDefaultDescription
childrenReactNodeNoneThe text to show; it moves with the card while the dialog opens and closes.
classNamestringNoneAdds extra classes to the text element.

Keyboard

KeysAction
Enter/SpaceOpen the dialog from the card.
Tab/Shift + TabCycle inside; focus is trapped.
EscapeClose it; focus returns to the card.

Accessibility

  • The card is a native button with aria-haspopup="dialog"; the dialog is role="dialog", labeled by MorphingDialogTitle and described by MorphingDialogDescription. Always render a title.
  • Controls go in MorphingDialogActions, which fades each one in after the flight.
  • Under reduced motion the flight is removed and the dialog only fades; describe informative media with alt.

All exports on this page

  • MorphingDialog — Morphing dialog: a card that grows into a dialog.
  • MorphingDialogActions — The dialog's buttons and other controls (a row by default).
  • MorphingDialogClose — The × button (added automatically by MorphingDialogContent unless showClose={false}).
  • MorphingDialogContent — The dialog.
  • MorphingDialogDescription — Text that only exists in the dialog.
  • MorphingDialogMedia — The picture (an <img>, a video poster, artwork) that flies from the card into the dialog.
  • MorphingDialogSubtitle — A line under the title (place, author, price) that also moves from the card into the dialog.
  • MorphingDialogTitle — The title.
  • MorphingDialogTrigger — The card.
  • defaultMorphingDialogLabels — The English MorphingDialogLabels used when labels is omitted; a partial labels prop is merged over it.

When to use the morphing dialog effect

  • Use it as a card to modal animation for gallery and product cards that open into detail, where the picture, title and subtitle fly from the card into the dialog instead of a modal appearing from nowhere.
  • Use it for a portfolio grid, a travel destination list or a recipe index, composing MorphingDialogTrigger with MorphingDialogContent and the shared Media, Title, Subtitle, Description and Actions pieces.
  • Keep the media's aspect ratio the same in the card and in the dialog, otherwise the shared image stretches during the flight and the morph looks unclean.
  • Skip it when the dialog is a form or a confirmation with no card to grow from; use Dialog for those, since a morph only makes sense when the trigger visibly becomes the content.
  • Pair it with Button inside MorphingDialogActions so each control fades itself, Badge for a category label on the card, and GlassCard grids to lay the triggers out.

Frequently asked questions

19 effects pages in all: browse them on All effects.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .