Menu

Shadcn Responsive Dialog: Card on Desktop, Sheet on Phones
📰

Shadcn Responsive Dialog: Card on Desktop, Sheet on Phones

DEV Community: mobile·Serban Dan Rusu·4 days ago
#rp3n2FgW
#devtomobile#devto#dev#dialog#sheet
Reading 0:00
15s threshold

TL;DR

A shadcn responsive dialog renders the Dialog above 768px and the Drawer, a bottom sheet you can drag down, below it. Put that switch inside one root component whose parts read the mode from context, so the content is written once and the open state survives a resize. Read the breakpoint with useSyncExternalStore so the server and the hydration render agree, and keep everything visible before the first tap identical in both modes, so nothing can flash.

The shadcn responsive dialog is the pattern from the shadcn/ui Drawer docs: a centered Dialog on desktop and a Drawer, a bottom sheet you can drag down, on phones. The recipe works, but it has you write the trigger and the header twice and pick the branch with a hook that guesses on the first render. Both cause bugs once you make a shadcn dialog mobile friendly this way: the copies drift apart, and the branch flips after mount.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.