Morph Panel
A React button that morphs into the panel it opens on a spring, blurring the label out and the form in. Ships with a feedback form and closes on Escape.
Installation
npx shadcn@latest add @minidev/morph-panel
MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/morph-panel.json
Usage
import { MorphPanel } from "@/components/ui/morph-panel"
export function Example() {
return (
<MorphPanel />
)
}
API reference
| Prop | Type | Default |
|---|---|---|
| labelTrigger text; also the panel's accessible name when it is a string. | React.ReactNode | "Feedback" |
| iconIcon before the label. | React.ReactNode | <MessageSquareIcon /> |
| widthPanel width in px. | number | 340 |
| anchorWhich corner of the trigger the panel grows from. | Anchor | "top-left" |
| openControlled open state. | boolean | - |
| defaultOpenInitial open state when uncontrolled. | boolean | false |
| onOpenChangeFires when the panel opens or closes. | (open: boolean) => void | - |
| childrenCustom panel as a render function. Receives close(), which also returns focus to the trigger. | (api: { close: () => void }) => React.ReactNode | - |
| onSubmitCalled with the text by the default feedback form. Return a promise to show "Sending…"; reject to let the user retry. | (text: string) => void | Promise<void> | - |
| className | string | - |
When to use
One surface grows from a pill into a panel, its corners easing from 10 to 16px, while the label blurs out and the content blurs in. No popover, no jump. Escape and an outside click close it and focus returns to the trigger; with reduced motion it swaps instantly. Default content is a feedback form with a sent state; pass a render function as children for your own panel. For a plain anchored panel use Popover; for a modal use Dialog.
Keyboard interactions
| Key | Action |
|---|---|
| EnterorSpace | On the trigger, opens the panel. |
| Escape | Closes the panel and returns focus to the trigger. |
| MetaEnterorCtrlEnter | In the feedback textarea, sends the note. |
| Tab | Moves through the fields and buttons in the panel. Focus is not trapped. |
Accessibility
- The open panel has
role="dialog"and anaria-labelfromlabelwhen it is a string, or "Panel" otherwise. It is not modal and has noaria-modal. - Escape returns focus to the trigger. An outside click closes it and leaves focus where the user clicked.
- The textarea has
aria-label="Feedback"andmaxLength={500}. The "Sent" message renders inside anaria-live="polite"element that mounts together with its text, so some screen readers may not announce it. - Under reduced motion the pill and panel swap instantly.
Frequently asked questions
How do I put my own form inside MorphPanel?
Pass a render function as children: <MorphPanel label="New note" width={300}>{({ close }) => <NoteForm onDone={close} />}</MorphPanel>. Calling close() shuts the panel and returns focus to the trigger. Focus your first field yourself; only the built-in feedback form focuses its textarea on open.
How do I send the built-in feedback form to my API?
Pass onSubmit, which receives the text. Return a promise to show "Sending…"; if it rejects, the form goes back to idle so the user can retry, but no error message is shown. The panel closes itself 1.5s after the "Sent" state.
Can I open MorphPanel from outside, or control it?
Yes. Pass open and onOpenChange to control it, or defaultOpen for the first render. anchor picks the trigger corner the panel grows from, for example "bottom-right" for a button in the bottom-right of the screen.
Dependencies
npm
Built from
Examples
Feedback with an async submit
Return a promise from onSubmit (here a 900ms stand-in for your API call) to show "Sending…"; a rejected promise puts the form back so the user can retry.
Your own panel
Pass a render function; close() shuts the panel and returns focus to the trigger.