Dialog
A modal dialog using the native HTML dialog element with focus trap, ESC to close, and htmx integration.
<rhx-dialog>
Examples
Basic Dialog
<rhx-button rhx-variant="brand"
data-rhx-dialog-open="demo-dialog">
Open Dialog
</rhx-button>
<rhx-dialog id="demo-dialog" rhx-label="Example Dialog">
<p>This is a basic dialog with a title and close button.</p>
<p>Press ESC or click the close button to dismiss.</p>
</rhx-dialog>
No Header
<rhx-button data-rhx-dialog-open="confirm-dialog">
Open Headerless Dialog
</rhx-button>
<rhx-dialog id="confirm-dialog" rhx-no-header="true">
<p>Are you sure you want to proceed?</p>
<rhx-button rhx-variant="neutral"
onclick="this.closest('dialog').close()">
Cancel
</rhx-button>
<rhx-button rhx-variant="brand"
onclick="this.closest('dialog').close()">
Confirm
</rhx-button>
</rhx-dialog>
With Footer
Size Variants
Use rhx-size to control the dialog width. Preset values: small, medium, large, full.
<!-- Small: 24rem -->
<rhx-dialog id="sm-dialog" rhx-label="Small" rhx-size="small">
<p>Compact dialog for confirmations.</p>
</rhx-dialog>
<!-- Medium: 32rem -->
<rhx-dialog id="md-dialog" rhx-label="Medium" rhx-size="medium">
<p>Standard dialog for simple forms.</p>
</rhx-dialog>
<!-- Large: 48rem -->
<rhx-dialog id="lg-dialog" rhx-label="Large" rhx-size="large">
<p>Wide dialog for multi-column layouts.</p>
</rhx-dialog>
<!-- Full: 90vw -->
<rhx-dialog id="full-dialog" rhx-label="Full" rhx-size="full">
<p>Full-width dialog for complex content.</p>
</rhx-dialog>
Custom Width
Pass any CSS width value to rhx-size for a custom dialog width.
<!-- Any CSS width value -->
<rhx-dialog id="custom-dialog"
rhx-label="Custom Width"
rhx-size="40rem">
<p>Custom width via CSS value.</p>
</rhx-dialog>
<!-- Other examples -->
<rhx-dialog rhx-size="600px" ...>
<rhx-dialog rhx-size="70vw" ...>
htmx Integration
<rhx-button rhx-variant="brand"
hx-get="/Docs/Components/Dialog?handler=EditForm"
hx-target="#htmx-dialog .rhx-dialog__body"
data-rhx-dialog-open="htmx-dialog">
Edit Profile
</rhx-button>
<rhx-dialog id="htmx-dialog" rhx-label="Edit Profile">
<p>Loading...</p>
</rhx-dialog>
Properties
| Property | Type | Default | Description |
|---|---|---|---|
rhx-open |
bool |
false |
Whether the dialog is initially open |
rhx-label |
string |
- |
Title text displayed in the dialog header |
rhx-no-header |
bool |
false |
Hides the default header with title and close button |
rhx-size |
string |
- |
Dialog width: small (24rem), medium (32rem), large (48rem), full (90vw), or any CSS width value |
rhx-focus-after-swap |
string |
"first" |
CSS selector or "first" for focus target after htmx swap; "none" to disable |
id |
string |
- |
Element ID used for dialog open triggers |
Accessibility
- Uses the native
<dialog>element with built-in focus trap and inert background. - ESC key closes the dialog.
- Dialog title is linked via
aria-labelledbyfor screen readers. - Close button has
aria-label="Close". - Focus is returned to the trigger element when the dialog closes.