Dialog
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.
Slots
4
| 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
|
||
[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. |
Attributes
6
| 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 |
|
|
Methods
6
| Method Name | Description |
|---|---|
cancel(returnValue: string)
|
|
setTrigger(element: HTMLElement)
|
|
toggle()
|
Manually toggles the dialog. |
show()
|
Manually opens the dialog. |
showModal()
|
|
close(returnValue: string)
|
Manually closes the dialog. |
Events
3
| 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. |
CSS Shadow Parts
7
| 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 Custom Properties
2
| 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
|
Design Tokens
20
| Token | Description | Copy |
|---|---|---|
--rh-color-surface-darker
|
Secondary surface (dark theme) |
|
--rh-font-family-body-text
|
Body text font family |
|
--rh-box-shadow-xl
|
Extra large box shadow |
|
--rh-color-text-primary
|
|
|
--rh-space-3xl
|
48px spacer |
|
--rh-font-family-heading
|
Heading font family |
|
--rh-font-size-heading-sm
|
h5 heading font size |
|
--rh-font-weight-body-text-regular
|
Regular font weight |
|
--rh-space-lg
|
16px spacer |
|
--rh-space-xl
|
24px spacer |
|
--rh-color-icon-secondary
|
|
|
--rh-color-surface-dark
|
Tertiary surface (dark theme) |
|
--rh-border-radius-default
|
3px border radius; Example: Card |
|
--rh-length-xl
|
24px length token |
|
--rh-space-2xl
|
32px spacer |
|
--rh-color-gray-90
|
Secondary surface (dark theme) |
|
--rh-opacity-60
|
60% opacity |
|
--rh-space-md
|
8px spacer |
|
--rh-space-sm
|
6px spacer |
|
--rh-color-surface-lightest
|
Primary surface (light theme) |
|
Other libraries
To learn more about our other libraries, visit this page.
Feedback
To give feedback about anything on this page, contact us.