Dialog
On this page
Importing
Add rh-dialog to your page with this import statement:
<script type="module">
import '@rhds/elements/rh-dialog/rh-dialog.js';
</script>
Copy to Clipboard
Copied!
Wrap lines
Overflow lines
To learn more about installing RHDS elements on your site using an import map read our getting started docs.
Usage
<rh-button id="first-modal-trigger">Open</rh-button>
<rh-dialog trigger="first-modal-trigger">
<h2 slot="header">Modal dialog with a header</h2>
<p>Lorem ipsum dolor sit amet, <a href="#foo">consectetur adipisicing</a> elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
anim id est laborum.</p>
<rh-cta slot="footer" href="#bar">Call to Action</rh-cta>
</rh-dialog>
<script type="module">
import '@rhds/elements/rh-button/rh-button.js';
import '@rhds/elements/rh-cta/rh-cta.js';
import '@rhds/elements/rh-dialog/rh-dialog.js';
</script>
Copy to Clipboard
Copied!
Wrap lines
Overflow lines
rh-dialog
A dialog displays important information to users without requiring them to navigate away from the page.
| Slot Name | Summary | Description |
|---|---|---|
header
|
The header is an optional slot that appears at the top of the dialog window. It should be a header tag (h2-h6). |
|
description
|
descriptive text providing additional context about the dialog |
Contains supplementary text that provides additional context or instructions for the dialog. Appears below the header and above the main content. This slot is optional and should be used when users need more information to understand the dialog's purpose or required actions. Usage guidelines:
|
[default]
|
The default slot can contain any type of content. When the header is not present this unnamed slot appear at the top of the dialog window (to the left of the close button). Otherwise it will appear beneath the header. |
|
|
Optional footer content. Good place to put action buttons. |
| Attribute | DOM Property | Description | Type | Default |
|---|---|---|---|---|
variant
|
variant |
The |
|
|
position
|
position |
|
|
|
accessible-label
|
accessibleLabel |
Use |
|
|
open
|
open |
|
|
|
trigger
|
trigger |
Optional ID of the trigger element |
|
|
type
|
type |
Use |
|
|
| Method Name | Description |
|---|---|
cancel(returnValue: string)
|
Cancels and closes the dialog, typically in response to user actions like clicking outside the dialog or pressing ESC. This method fires a cancelable Usage guidelines
|
setTrigger(element: HTMLElement)
|
Programmatically sets the trigger element for the dialog. This method assigns an element as the dialog's trigger and attaches click
event listeners. When the trigger is clicked, the dialog opens. Use this
when you need to dynamically change the trigger element or set a trigger
that isn't specified via the Usage guidelines
Accessibility
|
toggle()
|
Manually toggles the dialog. |
show()
|
Manually opens the dialog. |
showModal()
|
Opens the dialog in modal mode. This method opens the dialog as a modal, which means it appears on top of other content and prevents interaction with the rest of the page until closed. This is the standard way to open a dialog. Usage guidelines
Accessibility
|
close(returnValue: string)
|
Manually closes the dialog. |
| Event Name | Description |
|---|---|
open
|
Fires when a user clicks on the trigger or manually opens a dialog. |
close
|
Fires when either a user clicks on either the close button or manually closes a dialog. |
cancel
|
Fires when a user clicks outside the dialog or hits ESC on their keyboard. |
| Part Name | Summary | Description |
|---|---|---|
dialog
|
The dialog element |
|
|
|
The dialog's close button |
|
content
|
The container for the dialog content |
|
header
|
The container for the optional dialog header |
|
description
|
The container for the optional dialog description in the header |
|
body
|
||
|
|
Actions footer container |
| CSS Property | Description | Default |
|---|---|---|
--rh-dialog-close-button-color |
Sets the dialog close button color. |
var(--rh-color-surface-lightest, #ffffff)
|
--rh-dialog-video-aspect-ratio |
16/9
|
| Token | Summary | Copy |
|---|---|---|
--rh-color-surface-darker
|
|
|
--rh-font-family-body-text
|
|
|
--rh-box-shadow-xl
|
|
|
--rh-color-text-primary
|
|
|
--rh-space-3xl
|
|
|
--rh-font-family-heading
|
|
|
--rh-font-size-heading-sm
|
|
|
--rh-font-weight-body-text-regular
|
|
|
--rh-space-lg
|
|
|
--rh-space-xl
|
|
|
--rh-color-icon-secondary
|
|
|
--rh-color-surface-dark
|
|
|
--rh-border-radius-default
|
|
|
--rh-length-xl
|
|
|
--rh-space-2xl
|
|
|
--rh-color-gray-90
|
|
|
--rh-opacity-60
|
|
|
--rh-space-md
|
|
|
--rh-space-sm
|
|
|
--rh-color-surface-lightest
|
|
Other libraries
To learn more about our other libraries, visit this page.
Feedback
To give feedback about anything on this page, contact us.