<cs-dialog>
StableLayoutSince 0.1

Dialogs appear above the page and require the user's immediate attention. Use them for confirmations, forms, or focused tasks that interrupt the main flow.

This is a standard dialog. You can put any content you want in here! Close Open Dialog

Examples

Without a Header

Headers are enabled by default. To render a dialog without a header, add the without-header attribute.

Look ma, no header! Sometimes you just need a clean, simple dialog. Close Open Dialog

Footers can be used to display titles and more. Use the footer slot to add a footer to the dialog.

Check out the footer below — it's a great place for actions and buttons. Close Open Dialog

Opening & Closing Declaratively

You can open and close dialogs with JavaScript by toggling the open attribute, but you can also do it declaratively. Add the data-dialog="open id" to any button on the page, where id is the ID of the dialog you want to open.

This dialog was opened declaratively — no JavaScript required! Close Open Dialog

Similarly, you can add data-dialog="close" to a button inside of a dialog to tell it to close.

Click the button in the footer to close this dialog declaratively. Close Open Dialog

Width

Use the --width custom property to set the dialog’s width.

This dialog is wider than the default — handy when you need more room for content. Close Open Dialog

Scrolling

By design, a dialog’s height will never exceed that of the viewport. As such, dialogs will not scroll with the page ensuring the header and footer are always accessible to the user.

Scroll down and give it a try!

Close
Open Dialog

Header Actions

The header shows a functional close button by default. You can use the header-actions slot to add additional buttons if needed.

You can add custom actions to the header, like the icon button up there! Close Open Dialog

Light Dismissal

If you want the dialog to close when the user clicks on the overlay, add the light-dismiss attribute.

This dialog will close when you click on the overlay. Close Open Dialog

Preventing the Dialog from Closing

By default, dialogs will close when the user clicks the close button or presses the Escape key. In most cases, the default behavior is the best behavior in terms of UX. However, there are situations where this may be undesirable, such as when data loss will occur.

To keep the dialog open in such cases, you can cancel the cs-hide event. When canceled, the dialog will remain open and pulse briefly to draw the user’s attention to it.

You can use event.detail.source to determine which element triggered the request to close. This example prevents the dialog from closing unless a specific button is clicked.

This dialog will only close when you click the button below. Only this button will close it Open Dialog

Initial Focus

To give focus to a specific element when the dialog opens, use the autofocus attribute.

Close Open Dialog

API

Importing

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/dialog/dialog.js';
import './cornerstone/components/dialog/dialog.js';
import CsDialog from '@cruglobal/cornerstone-components/react/dialog/index.js';

Slots

Learn more about using slots.

NameDescription
(default)The dialog's main content.
footerThe dialog's footer, usually one or more buttons representing various options.
header-actionsOptional actions to add to the header. Works best with <cs-button>.
labelThe dialog's label. Alternatively, you can use the label attribute.

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
labellabelThe dialog's label as displayed in the header. You should always include a relevant label, as it is required for proper accessibility. If you need to display HTML, use the label slot instead.string''Yes
lightDismisslight-dismissWhen enabled, the dialog will be closed when the user clicks outside of it.booleanfalse
openopenIndicates whether or not the dialog is open. Toggle this attribute to show and hide the dialog.booleanfalseYes
ssrFooterssr-footerOnly required for SSR. Set to true if you're slotting in a footer element so the server-rendered markup includes the footer before the component hydrates on the client.booleanfalse
withoutHeaderwithout-headerDisables the header. This will also remove the default close button.booleanfalseYes

Events

Learn more about events.

NameDescription
cs-after-hideEmitted after the dialog closes and all animations are complete.
cs-after-showEmitted after the dialog opens and all animations are complete.
cs-hideEmitted when the dialog is requested to close. Calling event.preventDefault() will prevent the dialog from closing. You can inspect event.detail.source to see which element caused the dialog to close. If the source is the dialog element itself, the user has pressed Escape or the dialog has been closed programmatically. Avoid using this unless closing the dialog will result in destructive behavior such as data loss.
cs-showEmitted when the dialog opens.

CSS Custom Properties

Learn more about CSS custom properties.

NameDescriptionDefault
--backdrop-filterA filter to apply to the backdrop behind the dialog.none
--hide-durationThe animation duration when hiding the dialog.var(--cs-transition-normal)
--show-durationThe animation duration when showing the dialog.var(--cs-transition-normal)
--spacingThe amount of space around and between the dialog's content.
--widthThe preferred width of the dialog. Note that the dialog will shrink to accommodate smaller screens.

CSS Parts

Learn more about CSS parts.

NameDescriptionCSS selector
bodyThe dialog's body.::part(body)
close-buttonThe close button, a <cs-button>.::part(close-button)
close-button__buttonThe close button's exported button part.::part(close-button__button)
dialogThe dialog's internal <dialog> element.::part(dialog)
footerThe dialog's footer.::part(footer)
headerThe dialog's header. This element wraps the title and header actions.::part(header)
header-actionsOptional actions to add to the header. Works best with <cs-button>.::part(header-actions)
titleThe dialog's title.::part(title)

Dependencies

This component automatically imports the following elements. Sub-dependencies, if any exist, are included in this list.