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
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 |
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.