Dismiss icon
A compact close button for dismissing or removing the element it sits in.
Sizes
Large is the default.
<.dismiss_icon size="small" />
<.dismiss_icon size="large" />
Hiding an element
phx-click
with
JS.hide
removes the surrounding element without a round trip to the server.
Selective testing skipped 312 tests in this run.
<div id="dismiss-icon-notice" style="display: flex; align-items: center; gap: 8px;">
<span>Selective testing skipped 312 tests in this run.</span>
<.dismiss_icon size="small" phx-click={JS.hide(to: "#dismiss-icon-notice")} />
</div>
Disabled
Disable it while the element cannot be dismissed, for example while a request is in flight.
<.dismiss_icon size="small" disabled />
<.dismiss_icon size="large" disabled />
Guidelines
- Alerts, banners, modals, and tags already include a dismiss icon. Use it on its own only when you build a custom surface that can be closed.
-
Use
smallin compact components such as tags and small alerts, andlarge, the default, everywhere else. -
Pass an event name to
on_dismisswhen the server decides what happens. To hide an element in the browser only, passphx-clickwithJS.hide, as banners and alerts do. -
The button always renders with
aria-label="Dismiss"andtype="button", so it never submits a surrounding form.
API reference
<.dismiss_icon>
| Attribute | Type | Default | Description |
|---|---|---|---|
|
on_dismiss
|
string
|
nil
|
Event to trigger when the dismiss icon is clicked
|
|
size
|
string
|
"large"
|
The size of the icon
"small""large"
|
Also accepts global attributes, including disabled.