MDUIDocs
Copy llms.txt linkCopy llms-full.txt linkView this page in MarkdownDiscuss this page with ChatGPTDiscuss full project docs with ChatGPT
Preset Colors
Custom Color
Extract from Wallpaper
Please select a wallpaper
Getting Started
AI-Assisted Development
Styles
Integration with Frameworks
Components
Functions
jq Library dialog alert confirm prompt snackbar getTheme setTheme getColorFromImage setColorScheme removeColorScheme loadLocale setLocale getLocale throttle observeResize breakpoint
Libraries

confirm

The confirm function wraps the <mdui-dialog> component and replaces the native window.confirm function. With this function, you can open a confirmation dialog without writing any HTML.

Usage

Import the function:

import { confirm } from 'mdui/functions/confirm.js';

Example:

open
<mdui-button class="example-button">open</mdui-button>

<script type="module">
  import { confirm } from "mdui/functions/confirm.js";

  const button = document.querySelector(".example-button");

  button.addEventListener("click", () => {
    confirm({
      headline: "Confirm Title",
      description: "Confirm description",
      confirmText: "OK",
      cancelText: "Cancel",
      onConfirm: () => console.log("confirmed"),
      onCancel: () => console.log("canceled"),
    });
  });
</script>

API

confirm(options: Options): Promise<void>

The function takes an Options object and returns a Promise. If the dialog is closed by clicking the confirm button, the Promise resolves. If the dialog is closed in any other way, the Promise is rejected.

Options

Property Type Default
headline string -
The title of the dialog.
description string -
The description of the dialog.
icon string -
The Material Icons name displayed at the top of the dialog.
closeOnEsc boolean false
Whether the dialog can be closed by pressing the Esc key. If set to true, the dialog closes when the Esc key is pressed.
closeOnOverlayClick boolean false
Whether the dialog can be closed by clicking on the overlay.
confirmText string OK
The text for the confirm button.
cancelText string Cancel
The text for the cancel button.
stackedActions boolean false
Whether to stack the bottom action buttons vertically.
queue string -

The queue name.

Queues are disabled by default. If this function is called multiple times, multiple dialogs will appear simultaneously.

If you provide a queue name, dialogs with the same name open one after another.

The dialog(), alert(), confirm(), and prompt() functions share the same queue if their queue names match.

onConfirm (dialog: Dialog) => void | boolean | Promise<void> -

Called when the confirm button is clicked.

The callback receives the dialog instance as its argument, and this also refers to it.

By default, clicking the confirm button closes the dialog. If the return value is false, the dialog remains open. If the return value is a promise, the dialog closes after the promise resolves.

onCancel (dialog: Dialog) => void | boolean | Promise<void> -

Called when the cancel button is clicked.

The callback receives the dialog instance as its argument, and this also refers to it.

By default, clicking the cancel button closes the dialog. If the return value is false, the dialog remains open. If the return value is a promise, the dialog closes after the promise resolves.

onOpen (dialog: Dialog) => void -

Called when the dialog starts to open.

The callback receives the dialog instance as its argument, and this also refers to it.

onOpened (dialog: Dialog) => void -

Called when the dialog's open animation completes.

The callback receives the dialog instance as its argument, and this also refers to it.

onClose (dialog: Dialog) => void -

Called when the dialog starts to close.

The callback receives the dialog instance as its argument, and this also refers to it.

onClosed (dialog: Dialog) => void -

Called when the dialog's close animation completes.

The callback receives the dialog instance as its argument, and this also refers to it.

onOverlayClick (dialog: Dialog) => void -

Called when the overlay is clicked.

The callback receives the dialog instance as its argument, and this also refers to it.

On this page