Menu

Change language

GitHub repo

Dialog

dialogui

Free-form modal primitive — composable from `Dialog`, `DialogTrigger`, `DialogContent`, and friends. Use for forms, info cards, pickers, and any custom modal layout. Hand-rolled runes behavior: portal, Escape/outside close, scroll lock, focus trap, and labelledby wiring.

When to use which

Decision Guide

Dialogs capture immediate user focus for critical actions. Sheets slide in from screen edges for deep secondary forms, while Popovers provide lightweight contextual cards.

ComponentRole
Dialogcurrent

Critical confirmations, destructive warnings, or focused single-purpose tasks requiring user resolution.

Modal Window
Sheet

Complex edit forms, filter panes, or shopping carts that retain underlying page context.

Off-Canvas Slide-Over
Drawer

Mobile bottom sheets, touch-friendly sliding panels, or secondary inspection trays.

Edge Panel / Bottom Sheet
Popover

Small contextual dropdowns, color pickers, date pickers, or inline configuration flyouts.

Contextual Floating Card
  • Urgent confirmation or focused prompt → Dialog
  • Side panel for deep form editing → Sheet (view)
  • Mobile bottom sheet or gesture tray → Drawer (view)
  • Anchored contextual flyout or controls → Popover (view)

Installation

$npx shadcn-svelte@latest add https://uipkge.dev/r/svelte/dialog.json
Manifest:https://uipkge.dev/r/svelte/dialog.jsonInstalls to:src/lib/components/ui/dialog/

Examples

Loading interactive previews…

Props

NameType / ValuesDefaultRequired
open

pass `open` once for an uncontrolled dialog with a custom default.

boolean—optional
modal

body scroll-lock, and autofocus, and the overlay stops intercepting pointer events so the page stays interactive (Radix `modal` parity).

booleantrueoptional
onOpenChange(open: boolean) => void—optional
childrenSnippet—optional

Schema

Type aliases from this item's source — use them to shape the data you pass in.

DialogContextValue
interface DialogContextValue {
  readonly open: boolean
  setOpen: (open: boolean) => void
  readonly titleId: string
  readonly descriptionId: string
  /** False renders non-modal: no focus trap, body scroll-lock, or autofocus
   *  (Radix `modal` parity). The overlay still renders unless the consumer
   *  hides it — like Radix, non-modal panels typically omit the overlay. */
  readonly modal: boolean
}

npm dependencies

Includes

Used by

Files installed (13)

  • src/lib/components/ui/dialog/Dialog.svelte1.3 kB
    <script lang="ts" module>
      import type { Snippet } from 'svelte'
    
      export interface DialogProps {
        /** Controlled open state. The initial value doubles as `defaultOpen` —
         *  pass `open` once for an uncontrolled dialog with a custom default. */
        open?: boolean
        /** When false the dialog is non-modal: content skips the focus trap,
         *  body scroll-lock, and autofocus, and the overlay stops intercepting
         *  pointer events so the page stays interactive (Radix `modal` parity). */
        modal?: boolean
        onOpenChange?: (open: boolean) => void
        children?: Snippet
      }
    
      let dialogIdCounter = 0
    </script>
    
    <script lang="ts">
      import { setDialogContext } from './context'
    
      let { open = $bindable(false), modal = true, onOpenChange, children }: DialogProps = $props()
    
      dialogIdCounter += 1
      const titleId = `uipkge-dialog-title-${dialogIdCounter}`
      const descriptionId = `uipkge-dialog-description-${dialogIdCounter}`
    
      function setOpen(next: boolean) {
        if (next === open) return
        open = next
        onOpenChange?.(next)
      }
    
      setDialogContext({
        get open() {
          return open
        },
        setOpen,
        get titleId() {
          return titleId
        },
        get descriptionId() {
          return descriptionId
        },
        get modal() {
          return modal
        },
      })
    </script>
    
    {@render children?.()}
    
  • src/lib/components/ui/dialog/DialogClose.svelte1.1 kB
  • src/lib/components/ui/dialog/DialogContent.svelte3.4 kB
  • src/lib/components/ui/dialog/DialogDescription.svelte0.7 kB
  • src/lib/components/ui/dialog/DialogFooter.svelte0.9 kB
  • src/lib/components/ui/dialog/DialogHeader.svelte0.6 kB
  • src/lib/components/ui/dialog/DialogOverlay.svelte2.3 kB
  • src/lib/components/ui/dialog/DialogScrollContent.svelte3.6 kB
  • src/lib/components/ui/dialog/DialogTitle.svelte0.7 kB
  • src/lib/components/ui/dialog/DialogTrigger.svelte1.1 kB
  • src/lib/components/ui/dialog/context.ts1 kB
  • src/lib/components/ui/dialog/portal.ts0.5 kB
  • src/lib/components/ui/dialog/index.ts0.9 kB

Raw manifest:https://uipkge.dev/r/svelte/dialog.json