Skip to main content

Starwind UI v3.7 is here with stable Vue and Svelte, the new Chart component, and full RTL support. Read the release notes

Example Dialog

This is a simple dialog example that demonstrates the basic functionality.

Your dialog content goes here.

Installation

Usage

---
import { Dialog, DialogTrigger, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription, DialogClose } from "@/components/starwind/dialog";
import { Button } from "@/components/starwind/button";
---
<Dialog>
<DialogTrigger asChild>
<Button>Open Dialog</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Example Dialog</DialogTitle>
<DialogDescription>
This is a simple dialog example that demonstrates the basic functionality.
</DialogDescription>
</DialogHeader>
<div class="py-4">Your dialog content goes here.</div>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline">Cancel</Button>
</DialogClose>
<Button>Save Changes</Button>
</DialogFooter>
</DialogContent>
</Dialog>

Composition

Use this structure for a dialog:

Dialog
├── DialogTrigger
└── DialogContent
├── DialogHeader
│ ├── DialogTitle
│ └── DialogDescription
└── DialogFooter

DialogContent includes a close button. Use DialogClose when another control also needs to close the dialog.

When to Use

Use Dialog for focused content that appears above the page, such as a form, settings panel, or details that require a user response.

With Form

Dialogs are commonly used with forms for data input.

Tip

Open up the dev tools console to see the form data on submission.

Edit profile

Make changes to your profile here. Click save when you're done.

Multiple Triggers

You can have multiple triggers open the same dialog, including external triggers outside the Dialog wrapper. Add an id to <Dialog /> and pass that ID through targetId on each external <DialogTrigger />.

Contact Us

Send us a message and we'll get back to you shortly.

This button is outside the Dialog component but opens the same dialog:

Nested Dialogs

New You can nest dialogs within other dialogs to create multi-level workflows. The nested dialog will appear on top of the parent dialog, and only the topmost dialog will close when pressing Escape or clicking outside.

Parent Dialog

This is the parent dialog. You can open a nested dialog from here.

Nested Dialog

This is the nested dialog. The parent will not close when clicking outside.

API Reference

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.

Dialog Trigger

Inherits button attributes.

Contains the following additional props:

Prop Type Default Toggle details
asChild boolean false
Description
Merges the component behavior and props into its child element.
Classification
Primitive override
Primitive prop
dialog.Trigger.asChild

Dialog Close

Inherits button attributes.

Contains the following additional props:

Prop Type Default Toggle details
asChild boolean false
Description
Merges the component behavior and props into its child element.
Classification
Primitive override
Primitive prop
dialog.Close.asChild

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Dialog.

Primitive API

Runtime API

Dialog primitive
createDialog from @starwind-ui/runtime/dialog

Changelog

View version history v2.2.0 5 releases

v2.2.0

  • Dialog close controls and headings follow the reading direction. Dialog content keeps the direction of the section that contains the dialog when it moves into a portal, including a section with the opposite dir.
  • In Vue, this component now needs Vue 3.5.21 or newer.
  • Internal code cleanup, such as unused code and import order. This cleanup does not change behavior.

v2.1.0

  • In Astro, DialogTrigger and DialogClose with asChild now make your own element a working control. Before, a button child gave a control that did nothing.
  • In Astro, an attribute that you set on DialogHeader and DialogFooter now wins over the component’s own default for the same attribute, such as role or aria-label.
  • In Svelte, a defined open that you pass when Dialog mounts now stays under your control, as in React and Vue. To change it, use bind: or update your state in the change callback. A form reset keeps it. If you pass undefined at mount, Dialog keeps its own state.
  • A non-modal Dialog no longer moves focus back to its trigger when you move to another control while it closes.

v2.0.3

  • Trigger and close buttons added or replaced after the dialog mounts now work without closing and reopening it.
  • Vue Dialog keeps its previous open state when an open or close action is canceled.

v2.0.2

  • The default export in index.ts now has a name, DialogParts, so framework tools show a clear name.

v2.0.0

  • Dialog now gets its behavior from Starwind Runtime. Runtime handles the modal state, focus, closing, and dialogs inside dialogs.
  • See the Dialog Primitive for the unstyled parts and the behavior API.