Dialog
<cs-dialog>
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.
Examples
Without a Header
Headers are enabled by default. To render a dialog without a header, add the without-header attribute.
Footer
Footers can be used to display titles and more. Use the footer slot to add a footer to the 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.
Similarly, you can add data-dialog="close" to a button inside of a dialog to tell it to close.
Width
Use the --cs-dialog-width custom property to set the dialog’s width.
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!
Header Actions
The header shows a functional close button by default. You can use the header-actions slot to add additional buttons if needed.
Light Dismissal
If you want the dialog to close when the user clicks on the overlay, add the light-dismiss attribute.
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.
Initial Focus
To give focus to a specific element when the dialog opens, use the autofocus attribute.
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.
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.
| Name | Description |
|---|---|
| (default) | The dialog's main content. |
footer | The dialog's footer, usually one or more buttons representing various options. |
header-actions | Optional actions to add to the header. Works best with <cs-button>. |
label | The dialog's label. Alternatively, you can use the label attribute. When without-header is set, a slotted label does not name the dialog; use the attribute. |
Attributes & Properties
Learn more about attributes and properties.
| Property | Attribute | Description | Type | Default | Reflects |
|---|---|---|---|---|---|
label | label | The 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. When without-header is set, only the attribute provides the dialog's accessible name. | string | '' | Yes |
lightDismiss | light-dismiss | When enabled, the dialog will be closed when the user clicks outside of it. | boolean | false | — |
open | open | Indicates whether or not the dialog is open. Toggle this attribute to show and hide the dialog. | boolean | false | Yes |
ssrFooter | ssr-footer | Only 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. | boolean | false | — |
ssrLabel | ssr-label | Only required for SSR. Set to true if you're slotting in a label element so the server-rendered markup names the dialog before the component hydrates on the client. | boolean | false | — |
withoutHeader | without-header | Disables the header. This will also remove the default close button. | boolean | false | Yes |
Events
Learn more about events.
| Name | Description |
|---|---|
cs-after-hide | Emitted after the dialog closes and all animations are complete. |
cs-after-show | Emitted after the dialog opens and all animations are complete. |
cs-hide | Emitted 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-show | Emitted when the dialog opens. |
CSS Custom Properties
Learn more about CSS custom properties.
| Name | Description | Default |
|---|---|---|
--cs-backdrop-filter | A filter to apply to the backdrop behind the dialog. | none |
--cs-dialog-spacing | The amount of space around and between the dialog's content. | var(--cs-space-l) |
--cs-dialog-width | The preferred width of the dialog. Note that the dialog will shrink to accommodate smaller screens. | 31rem |
--cs-hide-duration | The animation duration when hiding the dialog. | var(--cs-transition-normal) |
--cs-show-duration | The animation duration when showing the dialog. | var(--cs-transition-normal) |
CSS Parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
body | The dialog's body. | ::part(body) |
close-button | The close button, a <cs-button>. | ::part(close-button) |
close-button__button | The close button's exported button part. | ::part(close-button__button) |
dialog | The dialog's internal <dialog> element. | ::part(dialog) |
footer | The dialog's footer. | ::part(footer) |
header | The dialog's header. This element wraps the title and header actions. | ::part(header) |
header-actions | Optional actions to add to the header. Works best with <cs-button>. | ::part(header-actions) |
title | The dialog's title. | ::part(title) |
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, are included in this list.

