--- layout: layouts/component.njk title: Alert Dialog description: A modal dialog that interrupts the user with important content and expects a response. toc: - label: Usage id: usage children: - label: Default id: usage-default - label: Jinja or Nunjucks id: usage-jinja --- {% from "macros/code_preview.njk" import code_preview %} {% from "macros/code_block.njk" import code_block %} {% from "components/dialog.njk" import dialog %} {% set code %}{% set footer %} {% endset %} {{ dialog( id="alert-dialog", title="Are you absolutely sure?", description="This action cannot be undone. This will permanently delete your account and remove your data from our servers.", trigger="Open alert dialog", trigger_attrs={"class": "btn-outline"}, footer=footer, close_button=false, close_on_overlay_click=false ) }}{% endset %} {{ code_preview("alert-dialog", code | prettyHtml) }}

Usage

Default

The Alert Dialog component uses the same Alpine.js code as the Dialog component with one small difference: we set initialCloseOnOverlayClick to false to prevent the dialog from closing when the overlay is clicked.

{{ code_block(code | prettyHtml) }}

Jinja or Nunjucks

If you use Jinja (or Nunjucks), you can use the dialog() macro directly, making sure to set close_on_overlay_click to False (or false for Nunjucks).

{% set raw_code %}{% raw %}{% set footer %} {% endset %} {{ dialog( id="demo-alert-dialog", title="Are you absolutely sure?", description="This action cannot be undone. This will permanently delete your account and remove your data from our servers.", trigger="Open Alert Dialog", trigger_attrs={"class": "btn-outline"}, footer=footer, close_button=False, close_on_overlay_click=False ) }}{% endraw %} {% endset%} {{ code_block(raw_code, "jinja") }}