Dialog
A window layered over the main page, built on the native
<dialog> element.
Installation
Shadwire follows shadcn/ui's open code model: the component's source is copied into your application and becomes yours. Install it with the CLI:
The dialog registry item installs these files:
-
app/components/ui_component.rb -
app/components/ui/dialog_component.rb -
app/components/ui/dialog/trigger_component.rb -
app/components/ui/dialog/content_component.rb -
app/components/ui/dialog/header_component.rb -
app/components/ui/dialog/footer_component.rb -
app/components/ui/dialog/title_component.rb -
app/components/ui/dialog/description_component.rb -
app/components/ui/dialog/close_component.rb -
app/components/ui/button_component.rb -
app/components/ui/icon_component.rb -
app/helpers/ui/dialog_helper.rb -
app/helpers/ui/button_helper.rb -
app/helpers/ui/icon_helper.rb -
app/javascript/controllers/ui_dialog_controller.js -
vendor/shadwire/shadwire.css
This component uses Stimulus, so the application needs importmap-rails and stimulus-rails with automatic controller loading.
Haven't installed the CLI yet? gem install shadwire, then shadwire init.
Usage
showModal() provides the
focus trap, the top layer, Esc
and focus restoration natively; the controller adds animations, closing
through the backdrop, and the wiring for
aria-labelledby/aria-describedby.
Or render the components directly:
Composition
Examples
Default
A profile form in a native <dialog>: focus trapping, Esc and focus restoration all come from the browser.
No backdrop close
close_on_backdrop: false ignores clicks outside the panel.
Custom footer
show_close_button: false drops the X; compose your own buttons with ui_dialog_close.
API reference
Every part accepts class /
class_name and
**attrs.
| Component | Argument | Default | Description |
|---|---|---|---|
Dialog |
close_on_backdrop |
true |
Closes on a click outside the panel (on the ::backdrop). |
Dialog::Trigger / Dialog::Close |
variant, size |
:outline, :default |
Wrap Ui::ButtonComponent with the open/close actions. |
Dialog::Content |
show_close_button |
true |
Renders the X button in the top-right corner. |
Dialog::Title / Dialog::Description |
— | — | Tied to the dialog through aria-labelledby/aria-describedby when it opens. |