Modal dialogs on the native <dialog> element.
Summary
Functions
Renders a confirmation dialog (role="alertdialog"). The cancel button is
focused first (via the hook, not the autofocus attribute, which browsers
can honour on page load even inside a closed dialog) so Enter never
confirms by accident; Escape cancels; clicking
the backdrop does nothing.
Renders a modal dialog.
Renders a sheet: a dialog docked to a viewport edge. Same API as dialog/1
plus side.
Functions
Renders a confirmation dialog (role="alertdialog"). The cancel button is
focused first (via the hook, not the autofocus attribute, which browsers
can honour on page load even inside a closed dialog) so Enter never
confirms by accident; Escape cancels; clicking
the backdrop does nothing.
<.alert_dialog id="delete-post" title="Delete this post?"
description="This permanently removes the post and its comments."
confirm="Delete" on_confirm={JS.push("delete", value: %{id: @post.id})} />on_confirm runs and then the dialog closes.
Attributes
id(:string) (required)show(:boolean) - Defaults tofalse.title(:string) (required)description(:string) - Defaults tonil.color(:string) - Defaults to"danger". Must be one of"danger","warning","info", or"accent".confirm(:string) - defaults to "Confirm". Defaults tonil.cancel(:string) - defaults to "Cancel". Defaults tonil.on_confirm(Phoenix.LiveView.JS) (required)on_close(Phoenix.LiveView.JS) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block
Renders a modal dialog.
Open it from the client with SlopUI.JS.open_dialog/1, or from the server
with show={@show}. Close buttons inside the dialog need no JavaScript at
all when wrapped in <form method="dialog">.
<.button phx-click={SlopJS.open_dialog("#confirm")}>Delete</.button>
<.dialog id="confirm" on_close={JS.push("cancelled")}>
<:title>Delete post?</:title>
<:description>This cannot be undone.</:description>
Body content
<:footer>
<form method="dialog"><.button variant="outline">Cancel</.button></form>
<.button color="danger" phx-click="delete">Delete</.button>
</:footer>
</.dialog>Accessibility: aria-labelledby and aria-describedby point at the title
and description. Focus is trapped and restored by the platform.
Attributes
id(:string) (required)show(:boolean) - server-controlled open state. Defaults tofalse.size(:string) - Defaults to"md". Must be one of"sm","md","lg","xl", or"full".placement(:string) - Defaults to"center". Must be one of"center", or"top".dismissable(:boolean) - close on Escape and backdrop click. Defaults totrue.close_button(:boolean) - Defaults totrue.on_open(Phoenix.LiveView.JS) - JS command run after the dialog opens. Defaults tonil.on_close(Phoenix.LiveView.JS) - JS command run after the dialog closes. Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
titledescriptioninner_blockfooter
Renders a sheet: a dialog docked to a viewport edge. Same API as dialog/1
plus side.
<.sheet id="filters" side="right">
<:title>Filters</:title>
...
</.sheet>Attributes
id(:string) (required)show(:boolean) - Defaults tofalse.side(:string) - Defaults to"right". Must be one of"right","left","top", or"bottom".size(:string) - Defaults to"md". Must be one of"sm","md","lg", or"xl".dismissable(:boolean) - Defaults totrue.close_button(:boolean) - Defaults totrue.on_open(Phoenix.LiveView.JS) - Defaults tonil.on_close(Phoenix.LiveView.JS) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
titledescriptioninner_blockfooter