Dialog

OverviewStyleGuidelinesCodeAccessibilityDemos

Installation

We recommend import maps when building pages with RHDS. Learn more about how to install on our getting started docs.

Red Hat CDN
<script type="importmap">
{
  "imports": {
    "@rhds/elements/": "https://www.redhatstatic.com/dx/v1-alpha/@rhds/elements@2.1.2/elements/",
  }
}
</script>
Copy to Clipboard Wrap lines
NPM
npm install @rhds/elements
Copy to Clipboard Wrap lines
JSPM
<script type="importmap">
Could not generate import map using JSPM: Cannot read properties of undefined (reading '@rhds/elements')
</script>
Copy to Clipboard Wrap lines

Add it to your page with this import statement

<script type="module">
  import '@rhds/elements/rh-dialog/rh-dialog.js';
</script>
Copy to Clipboard Wrap lines

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 Wrap lines

rh-dialog

A dialog displays important information to users without requiring them to navigate away from the page.

Slots 3
Slot Name Description

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.

header

The header is an optional slot that appears at the top of the dialog window. It should be a header tag (h2-h6).

footer

Optional footer content. Good place to put action buttons.

Attributes 6
Attribute DOM Property Description Type Default
variant variant

The variant controls the width of the dialog. There are three options: small, medium and large. The default is large.

'small' | 'medium' | 'large' | undefined
unknown
position position

position="top" aligns the dialog with the top of the page

'top' | undefined
unknown
accessible-label accessibleLabel

Use accessible-label="My custom label" to specify the dialog's accessible name. Defaults to the name of the dialog trigger if no attribute is set and no headings exist in the modal. See Dialog's Accessibility page for more info.

string | undefined
unknown
open open

open / open="open" declaratively opens the dialog

boolean
false
trigger trigger

Optional ID of the trigger element

string | undefined
unknown
type type

Use type="video" to embed a video player into a dialog.

'video' | undefined
unknown
Methods 5
Method Name Description
setTrigger(element: HTMLElement)
toggle()

Manually toggles the dialog.

dialog.toggle();
show()

Manually opens the dialog.

dialog.show();
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 Description
overlay

@deprecated in favor of the backdrop pseudo-element. The dialog overlay which lies under the dialog and above the page body

dialog

The dialog element

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

close-button

The dialog's close button

footer

Actions footer container

CSS Custom Properties 4
CSS Property Description Default
--rh-dialog-video-aspect-ratio

Aspect ratio for the video inside the dialog

16/9
--rh-dialog-close-button-color

Sets the dialog close button color.

var(--rh-color-icon-secondary-on-dark, #ffffff)
--rh-dialog-backdrop-background-color

Sets the background color for the native HTML dialog element's backdrop pseudo-element

rgba(3, 3, 3, 0.62)
--rh-dialog-overlay-background-color

@deprecated Sets the background color for the #overlay <div>. Use --rh-dialog-backdrop-background-color instead.

transparent
Design Tokens 18
Token Copy
--rh-border-radius-default
Full CSS Variable Permalink to this token
--rh-box-shadow-xl
Full CSS Variable Permalink to this token
--rh-color-gray-90-rgb
Full CSS Variable Permalink to this token
--rh-color-icon-secondary
Full CSS Variable Permalink to this token
--rh-color-surface
Full CSS Variable Permalink to this token
--rh-color-text-primary
Full CSS Variable Permalink to this token
--rh-font-family-body-text
Full CSS Variable Permalink to this token
--rh-font-family-heading
Full CSS Variable Permalink to this token
--rh-font-size-heading-sm
Full CSS Variable Permalink to this token
--rh-font-weight-body-text-regular
Full CSS Variable Permalink to this token
--rh-length-xl
Full CSS Variable Permalink to this token
--rh-opacity-60
Full CSS Variable Permalink to this token
--rh-space-2xl
Full CSS Variable Permalink to this token
--rh-space-3xl
Full CSS Variable Permalink to this token
--rh-space-lg
Full CSS Variable Permalink to this token
--rh-space-md
Full CSS Variable Permalink to this token
--rh-space-sm
Full CSS Variable Permalink to this token
--rh-space-xl
Full CSS Variable Permalink to this token