Skip to main content

Starwind UI v3.0 beta is now available! Read the migration guide

Example Dialog

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

Your dialog content goes here.

Installation

Framework Availability

Astro Available React Available

Dialog is available for Astro and React.

Usage

General Notes

All you really need is the Dialog,DialogTrigger, and DialogContent. The rest is up to you. As examples, the search feature and mobile navbar of this site are built on top of the Dialog component.

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.

Runtime example adjustment

Dialog content now gets its transition timing from the Runtime component and stylesheet, so the legacy animationDuration prop is no longer needed.

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:

Runtime example adjustment

External Runtime dialog triggers identify their dialog with targetId; the former for prop is no longer part of the styled trigger API.

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 Astro styled component. Standard HTML attributes remain available through the inherited interfaces noted below. 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
Wrapper prop

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
Wrapper prop

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

v2.0.0

  • Rebuilt Dialog on Starwind Runtime for modal state, focus management, dismissal, and nesting.
  • See the Dialog Primitive for the underlying unstyled anatomy and behavior API.