Skip to content

Alert Dialog ​

A dialog that needs a response from the user before they continue.

vue
<script setup lang="ts">
import { AlertDialog } from '@vase-ui/vue/alert-dialog';
import styles from './index.module.css';

const backdropHiddenClass = styles.BackdropHidden;
const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <AlertDialog.Root>
    <AlertDialog.Trigger data-color="red" :class="styles.Button">Discard draft</AlertDialog.Trigger>
    <AlertDialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <AlertDialog.Backdrop :class="styles.Backdrop" />
      </Transition>
      <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
        <AlertDialog.Popup :class="styles.Popup">
          <div :class="styles.Intro">
            <AlertDialog.Title :class="styles.Title">Discard draft?</AlertDialog.Title>
            <AlertDialog.Description :class="styles.Description">
              You can't undo this action.
            </AlertDialog.Description>
          </div>
          <div :class="styles.Actions">
            <AlertDialog.Close :class="styles.Button">Cancel</AlertDialog.Close>
            <AlertDialog.Close data-color="red" :class="styles.Button">Discard</AlertDialog.Close>
          </div>
        </AlertDialog.Popup>
      </Transition>
    </AlertDialog.Portal>
  </AlertDialog.Root>
</template>
css
.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  &[data-color='red'] {
    color: oklch(50.5% 0.213 27.518deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.4% 0.191 22.216deg);
    }
  }

  @media (hover: hover) {
    &:hover:not(:disabled) {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active:not(:disabled) {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }

  &:disabled {
    color: oklch(55.6% 0 0deg);
    border-color: oklch(55.6% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.8% 0 0deg);
      border-color: oklch(70.8% 0 0deg);
    }
  }
}

.Backdrop {
  position: fixed;
  inset: 0;
  background-color: black;
  opacity: 0.2;
  transition: opacity 150ms;

  /* iOS 26+: Ensure the backdrop covers the entire visible viewport. */
  @supports (-webkit-touch-callout: none) {
    position: absolute;
    min-height: 100dvh;
  }

  @media (prefers-color-scheme: dark) {
    opacity: 0.5;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the part. */
.BackdropHidden {
  opacity: 0;
}

.Popup {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24rem;
  max-width: calc(100% - 3rem);
  margin-top: -2rem;
  padding: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  color: oklch(14.5% 0 0deg);
  box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
  transition:
    transform 100ms ease-out,
    opacity 100ms ease-out;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
    box-shadow: none;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the part. */
.PopupHidden {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.98);
}

.Intro {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.Title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.5rem;
  font-weight: 700;
}

.Description {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(43.9% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: oklch(70.8% 0 0deg);
  }
}

.Actions {
  display: flex;
  justify-content: end;
  gap: 0.75rem;
}
vue
<script setup lang="ts">
import { AlertDialog } from '@vase-ui/vue/alert-dialog';

const backdropHiddenClass = 'opacity-0';
const popupHiddenClass = 'scale-[0.98] opacity-0';

const buttonClasses =
  'flex h-8 items-center justify-center gap-2 border border-neutral-950 dark:border-white bg-white dark:bg-neutral-950 px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 dark:text-white select-none hover:not-disabled:bg-neutral-100 dark:hover:not-disabled:bg-neutral-800 active:not-disabled:bg-neutral-200 dark:active:not-disabled:bg-neutral-700 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400';

const dangerButtonClasses = `${buttonClasses} text-red-700 dark:text-red-400`;
</script>

<template>
  <AlertDialog.Root>
    <AlertDialog.Trigger :class="dangerButtonClasses">Discard draft</AlertDialog.Trigger>
    <AlertDialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <AlertDialog.Backdrop
          class="fixed inset-0 bg-black/20 dark:bg-black/50 transition-opacity duration-150 supports-[-webkit-touch-callout:none]:absolute supports-[-webkit-touch-callout:none]:min-h-dvh"
        />
      </Transition>
      <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
        <AlertDialog.Popup
          class="fixed top-1/2 left-1/2 -mt-8 flex w-96 max-w-[calc(100%-3rem)] -translate-x-1/2 -translate-y-1/2 flex-col gap-4 bg-white dark:bg-neutral-950 p-4 text-neutral-950 dark:text-white border border-neutral-950 dark:border-white shadow-[0.25rem_0.25rem_0] shadow-black/12 dark:shadow-none transition-[scale,opacity] duration-100 ease-out"
        >
          <div class="flex flex-col gap-1">
            <AlertDialog.Title class="text-base font-bold">Discard draft?</AlertDialog.Title>
            <AlertDialog.Description class="text-sm text-neutral-600 dark:text-neutral-400">
              You can't undo this action.
            </AlertDialog.Description>
          </div>
          <div class="flex justify-end gap-3">
            <AlertDialog.Close :class="buttonClasses">Cancel</AlertDialog.Close>
            <AlertDialog.Close :class="dangerButtonClasses">Discard</AlertDialog.Close>
          </div>
        </AlertDialog.Popup>
      </Transition>
    </AlertDialog.Portal>
  </AlertDialog.Root>
</template>

Anatomy ​

Import the component and assemble its parts:

vue
<script setup lang="ts">
import { AlertDialog } from '@vase-ui/vue/alert-dialog';
</script>

<template>
  <AlertDialog.Root>
    <AlertDialog.Trigger />
    <AlertDialog.Portal>
      <AlertDialog.Backdrop />
      <AlertDialog.Viewport>
        <AlertDialog.Popup>
          <AlertDialog.Title />
          <AlertDialog.Description />
          <AlertDialog.Close />
        </AlertDialog.Popup>
      </AlertDialog.Viewport>
    </AlertDialog.Portal>
  </AlertDialog.Root>
</template>

Examples ​

Detached triggers ​

A trigger can be inside or outside AlertDialog.Root. For a simple interaction, put AlertDialog.Trigger inside AlertDialog.Root, as the example at the top of this page does.

When the content of the alert dialog cannot be next to its trigger, use a detached trigger. Put AlertDialog.Trigger outside AlertDialog.Root, and connect the two with a handle from AlertDialog.createHandle().

The methods of the handle, such as open() and openWithPayload(), act only while an AlertDialog.Root with the same handle is mounted. The handle ignores a call before a root mounts or after it unmounts. When two mounted roots have the same handle, the handle acts on the root that took it last. Each root that mounts starts from a new state. It does not run an ignored call, and it does not keep the open state of an earlier root.

vue
<script setup lang="ts">
import { AlertDialog } from '@vase-ui/vue/alert-dialog';

const demoAlertDialog = AlertDialog.createHandle();
</script>

<template>
  <AlertDialog.Trigger :handle="demoAlertDialog">Open</AlertDialog.Trigger>

  <AlertDialog.Root :handle="demoAlertDialog">
    <AlertDialog.Portal>
      <AlertDialog.Popup>
        <AlertDialog.Title>Alert dialog</AlertDialog.Title>
      </AlertDialog.Popup>
    </AlertDialog.Portal>
  </AlertDialog.Root>
</template>
vue
<script setup lang="ts">
import { AlertDialog } from '@vase-ui/vue/alert-dialog';
import styles from '../../_index.module.css';

const backdropHiddenClass = styles.BackdropHidden;
const popupHiddenClass = styles.PopupHidden;

const demoAlertDialog = AlertDialog.createHandle();
</script>

<template>
  <AlertDialog.Trigger :class="[styles.Button, styles.DangerButton]" :handle="demoAlertDialog">
    Discard draft
  </AlertDialog.Trigger>

  <AlertDialog.Root :handle="demoAlertDialog">
    <AlertDialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <AlertDialog.Backdrop :class="styles.Backdrop" />
      </Transition>
      <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
        <AlertDialog.Popup :class="styles.Popup">
          <div :class="styles.Intro">
            <AlertDialog.Title :class="styles.Title">Discard draft?</AlertDialog.Title>
            <AlertDialog.Description :class="styles.Description">
              This action cannot be undone.
            </AlertDialog.Description>
          </div>
          <div :class="styles.Actions">
            <AlertDialog.Close :class="styles.Button">Cancel</AlertDialog.Close>
            <AlertDialog.Close :class="[styles.Button, styles.DangerButton]">
              Discard
            </AlertDialog.Close>
          </div>
        </AlertDialog.Popup>
      </Transition>
    </AlertDialog.Portal>
  </AlertDialog.Root>
</template>
css
.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  @media (hover: hover) {
    &:hover:not(:disabled) {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active:not(:disabled) {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }

  &:disabled {
    color: oklch(55.6% 0 0deg);
    border-color: oklch(55.6% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.8% 0 0deg);
      border-color: oklch(70.8% 0 0deg);
    }
  }
}

.DangerButton {
  color: oklch(50.5% 0.213 27.518deg);

  @media (prefers-color-scheme: dark) {
    color: oklch(70.4% 0.191 22.216deg);
  }
}

.Backdrop {
  position: fixed;
  inset: 0;
  background-color: black;
  opacity: 0.2;
  transition: opacity 150ms;

  /* iOS 26+: Ensure the backdrop covers the entire visible viewport. */
  @supports (-webkit-touch-callout: none) {
    position: absolute;
    min-height: 100dvh;
  }

  @media (prefers-color-scheme: dark) {
    opacity: 0.5;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the part. */
.BackdropHidden {
  opacity: 0;
}

.Popup {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24rem;
  max-width: calc(100% - 3rem);
  margin-top: -2rem;
  padding: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  color: oklch(14.5% 0 0deg);
  box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
  transition:
    transform 100ms ease-out,
    opacity 100ms ease-out;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
    box-shadow: none;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the part. */
.PopupHidden {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.98);
}

.Intro {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.Title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.5rem;
  font-weight: 700;
}

.Description {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(43.9% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: oklch(70.8% 0 0deg);
  }
}

.Actions {
  display: flex;
  justify-content: end;
  gap: 0.75rem;
}

.Container {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
vue
<script setup lang="ts">
import { AlertDialog } from '@vase-ui/vue/alert-dialog';

const backdropHiddenClass = 'opacity-0';
const popupHiddenClass = 'scale-[0.98] opacity-0';

const demoAlertDialog = AlertDialog.createHandle();

const buttonClasses =
  'flex h-8 items-center justify-center gap-2 border border-neutral-950 dark:border-white bg-white dark:bg-neutral-950 px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 dark:text-white select-none hover:not-disabled:bg-neutral-100 dark:hover:not-disabled:bg-neutral-800 active:not-disabled:bg-neutral-200 dark:active:not-disabled:bg-neutral-700 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400';

const dangerButtonClasses = `${buttonClasses} text-red-700 dark:text-red-400`;
</script>

<template>
  <AlertDialog.Trigger :class="dangerButtonClasses" :handle="demoAlertDialog">
    Discard draft
  </AlertDialog.Trigger>

  <AlertDialog.Root :handle="demoAlertDialog">
    <AlertDialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <AlertDialog.Backdrop
          class="fixed inset-0 bg-black/20 dark:bg-black/50 transition-opacity duration-150 supports-[-webkit-touch-callout:none]:absolute supports-[-webkit-touch-callout:none]:min-h-dvh"
        />
      </Transition>
      <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
        <AlertDialog.Popup
          class="fixed top-1/2 left-1/2 -mt-8 flex w-96 max-w-[calc(100%-3rem)] -translate-x-1/2 -translate-y-1/2 flex-col gap-4 bg-white dark:bg-neutral-950 p-4 text-neutral-950 dark:text-white border border-neutral-950 dark:border-white shadow-[0.25rem_0.25rem_0] shadow-black/12 dark:shadow-none transition-[scale,opacity] duration-100 ease-out"
        >
          <div class="flex flex-col gap-1">
            <AlertDialog.Title class="text-base font-bold">Discard draft?</AlertDialog.Title>
            <AlertDialog.Description class="text-sm text-neutral-600 dark:text-neutral-400">
              This action cannot be undone.
            </AlertDialog.Description>
          </div>
          <div class="flex justify-end gap-3">
            <AlertDialog.Close :class="buttonClasses">Cancel</AlertDialog.Close>
            <AlertDialog.Close :class="dangerButtonClasses"> Discard </AlertDialog.Close>
          </div>
        </AlertDialog.Popup>
      </Transition>
    </AlertDialog.Portal>
  </AlertDialog.Root>
</template>

Multiple triggers ​

More than one trigger can open the same alert dialog. Give the same handle to more than one detached trigger, or put more than one AlertDialog.Trigger in one AlertDialog.Root.

vue
<script setup lang="ts">
import { AlertDialog } from '@vase-ui/vue/alert-dialog';
</script>

<template>
  <AlertDialog.Root>
    <AlertDialog.Trigger>Trigger 1</AlertDialog.Trigger>
    <AlertDialog.Trigger>Trigger 2</AlertDialog.Trigger>
    <AlertDialog.Portal>
      <AlertDialog.Popup>
        <AlertDialog.Title>Alert dialog</AlertDialog.Title>
      </AlertDialog.Popup>
    </AlertDialog.Portal>
  </AlertDialog.Root>
</template>
vue
<script setup lang="ts">
import { AlertDialog } from '@vase-ui/vue/alert-dialog';

const demoAlertDialog = AlertDialog.createHandle();
</script>

<template>
  <AlertDialog.Trigger :handle="demoAlertDialog">Trigger 1</AlertDialog.Trigger>
  <AlertDialog.Trigger :handle="demoAlertDialog">Trigger 2</AlertDialog.Trigger>

  <AlertDialog.Root :handle="demoAlertDialog">
    <AlertDialog.Portal>
      <AlertDialog.Popup>
        <AlertDialog.Title>Alert dialog</AlertDialog.Title>
      </AlertDialog.Popup>
    </AlertDialog.Portal>
  </AlertDialog.Root>
</template>

The alert dialog can show different content for each trigger. Give a payload to each AlertDialog.Trigger. The default slot of AlertDialog.Root gets the payload of the active trigger.

The type argument of createHandle() gives the type of the payload:

vue
<script setup lang="ts">
import { AlertDialog } from '@vase-ui/vue/alert-dialog';

const demoAlertDialog = AlertDialog.createHandle<{ message: string }>();
</script>

<template>
  <AlertDialog.Trigger :handle="demoAlertDialog" :payload="{ message: 'Trigger 1' }">
    Trigger 1
  </AlertDialog.Trigger>
  <AlertDialog.Trigger :handle="demoAlertDialog" :payload="{ message: 'Trigger 2' }">
    Trigger 2
  </AlertDialog.Trigger>

  <AlertDialog.Root :handle="demoAlertDialog">
    <template #default="{ payload }">
      <AlertDialog.Portal>
        <AlertDialog.Popup>
          <AlertDialog.Title>Alert dialog</AlertDialog.Title>
          <AlertDialog.Description v-if="payload !== undefined">
            Confirming {{ payload.message }}
          </AlertDialog.Description>
        </AlertDialog.Popup>
      </AlertDialog.Portal>
    </template>
  </AlertDialog.Root>
</template>

Controlled mode with multiple triggers ​

To control the open state, bind it with v-model:open on AlertDialog.Root. With more than one trigger, also bind the active trigger with v-model:trigger-id, and give an id to each AlertDialog.Trigger.

The openChange event gives eventDetails as its second argument. Its trigger is the element of the trigger that started the change.

vue
<script setup lang="ts">
import { shallowRef } from 'vue';
import { AlertDialog } from '@vase-ui/vue/alert-dialog';
import styles from '../../_index.module.css';

const backdropHiddenClass = styles.BackdropHidden;
const popupHiddenClass = styles.PopupHidden;

type AlertPayload = { message: string };

const demoAlertDialog = AlertDialog.createHandle<AlertPayload>();

const open = shallowRef(false);
const triggerId = shallowRef<string | null>(null);

function handleOpenChange(isOpen: boolean, eventDetails: AlertDialog.Root.ChangeEventDetails) {
  open.value = isOpen;
  triggerId.value = eventDetails.trigger?.id ?? null;
}

function openProgrammatically() {
  triggerId.value = 'alert-trigger-2';
  open.value = true;
}
</script>

<template>
  <div :class="styles.Container">
    <AlertDialog.Trigger
      :class="[styles.Button, styles.DangerButton]"
      :handle="demoAlertDialog"
      id="alert-trigger-1"
      :payload="{ message: 'Discard draft?' }"
    >
      Discard
    </AlertDialog.Trigger>

    <AlertDialog.Trigger
      :class="[styles.Button, styles.DangerButton]"
      :handle="demoAlertDialog"
      id="alert-trigger-2"
      :payload="{ message: 'Delete project?' }"
    >
      Delete
    </AlertDialog.Trigger>

    <AlertDialog.Trigger
      :class="styles.Button"
      :handle="demoAlertDialog"
      id="alert-trigger-3"
      :payload="{ message: 'Sign out?' }"
    >
      Sign out
    </AlertDialog.Trigger>

    <button :class="styles.Button" type="button" @click="openProgrammatically">
      Open programmatically
    </button>
  </div>

  <AlertDialog.Root
    :handle="demoAlertDialog"
    :open="open"
    :trigger-id="triggerId"
    @open-change="handleOpenChange"
  >
    <template #default="{ payload }">
      <AlertDialog.Portal>
        <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
          <AlertDialog.Backdrop :class="styles.Backdrop" />
        </Transition>
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <AlertDialog.Popup :class="styles.Popup">
            <div :class="styles.Intro">
              <AlertDialog.Title :class="styles.Title">
                {{ payload?.message ?? 'Are you sure?' }}
              </AlertDialog.Title>
              <AlertDialog.Description :class="styles.Description">
                This action cannot be undone.
              </AlertDialog.Description>
            </div>
            <div :class="styles.Actions">
              <AlertDialog.Close :class="styles.Button">Cancel</AlertDialog.Close>
              <AlertDialog.Close :class="[styles.Button, styles.DangerButton]">
                Confirm
              </AlertDialog.Close>
            </div>
          </AlertDialog.Popup>
        </Transition>
      </AlertDialog.Portal>
    </template>
  </AlertDialog.Root>
</template>
css
.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  @media (hover: hover) {
    &:hover:not(:disabled) {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active:not(:disabled) {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }

  &:disabled {
    color: oklch(55.6% 0 0deg);
    border-color: oklch(55.6% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.8% 0 0deg);
      border-color: oklch(70.8% 0 0deg);
    }
  }
}

.DangerButton {
  color: oklch(50.5% 0.213 27.518deg);

  @media (prefers-color-scheme: dark) {
    color: oklch(70.4% 0.191 22.216deg);
  }
}

.Backdrop {
  position: fixed;
  inset: 0;
  background-color: black;
  opacity: 0.2;
  transition: opacity 150ms;

  /* iOS 26+: Ensure the backdrop covers the entire visible viewport. */
  @supports (-webkit-touch-callout: none) {
    position: absolute;
    min-height: 100dvh;
  }

  @media (prefers-color-scheme: dark) {
    opacity: 0.5;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the part. */
.BackdropHidden {
  opacity: 0;
}

.Popup {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24rem;
  max-width: calc(100% - 3rem);
  margin-top: -2rem;
  padding: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  color: oklch(14.5% 0 0deg);
  box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
  transition:
    transform 100ms ease-out,
    opacity 100ms ease-out;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
    box-shadow: none;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the part. */
.PopupHidden {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.98);
}

.Intro {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.Title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.5rem;
  font-weight: 700;
}

.Description {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(43.9% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: oklch(70.8% 0 0deg);
  }
}

.Actions {
  display: flex;
  justify-content: end;
  gap: 0.75rem;
}

.Container {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
vue
<script setup lang="ts">
import { shallowRef } from 'vue';
import { AlertDialog } from '@vase-ui/vue/alert-dialog';

const backdropHiddenClass = 'opacity-0';
const popupHiddenClass = 'scale-[0.98] opacity-0';

type AlertPayload = { message: string };

const demoAlertDialog = AlertDialog.createHandle<AlertPayload>();

const buttonClasses =
  'flex h-8 items-center justify-center gap-2 border border-neutral-950 dark:border-white bg-white dark:bg-neutral-950 px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 dark:text-white select-none hover:not-disabled:bg-neutral-100 dark:hover:not-disabled:bg-neutral-800 active:not-disabled:bg-neutral-200 dark:active:not-disabled:bg-neutral-700 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400';

const dangerButtonClasses = `${buttonClasses} text-red-700 dark:text-red-400`;

const open = shallowRef(false);
const triggerId = shallowRef<string | null>(null);

function handleOpenChange(isOpen: boolean, eventDetails: AlertDialog.Root.ChangeEventDetails) {
  open.value = isOpen;
  triggerId.value = eventDetails.trigger?.id ?? null;
}

function openProgrammatically() {
  triggerId.value = 'alert-trigger-2';
  open.value = true;
}
</script>

<template>
  <div class="flex flex-wrap gap-2 justify-center">
    <AlertDialog.Trigger
      :class="dangerButtonClasses"
      :handle="demoAlertDialog"
      id="alert-trigger-1"
      :payload="{ message: 'Discard draft?' }"
    >
      Discard
    </AlertDialog.Trigger>

    <AlertDialog.Trigger
      :class="dangerButtonClasses"
      :handle="demoAlertDialog"
      id="alert-trigger-2"
      :payload="{ message: 'Delete project?' }"
    >
      Delete
    </AlertDialog.Trigger>

    <AlertDialog.Trigger
      :class="buttonClasses"
      :handle="demoAlertDialog"
      id="alert-trigger-3"
      :payload="{ message: 'Sign out?' }"
    >
      Sign out
    </AlertDialog.Trigger>

    <button :class="buttonClasses" type="button" @click="openProgrammatically">
      Open programmatically
    </button>
  </div>

  <AlertDialog.Root
    :handle="demoAlertDialog"
    :open="open"
    :trigger-id="triggerId"
    @open-change="handleOpenChange"
  >
    <template #default="{ payload }">
      <AlertDialog.Portal>
        <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
          <AlertDialog.Backdrop
            class="fixed inset-0 bg-black/20 dark:bg-black/50 transition-opacity duration-150 supports-[-webkit-touch-callout:none]:absolute supports-[-webkit-touch-callout:none]:min-h-dvh"
          />
        </Transition>
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <AlertDialog.Popup
            class="fixed top-1/2 left-1/2 -mt-8 flex w-96 max-w-[calc(100%-3rem)] -translate-x-1/2 -translate-y-1/2 flex-col gap-4 bg-white dark:bg-neutral-950 p-4 text-neutral-950 dark:text-white border border-neutral-950 dark:border-white shadow-[0.25rem_0.25rem_0] shadow-black/12 dark:shadow-none transition-[scale,opacity] duration-100 ease-out"
          >
            <div class="flex flex-col gap-1">
              <AlertDialog.Title class="text-base font-bold">
                {{ payload?.message ?? 'Are you sure?' }}
              </AlertDialog.Title>
              <AlertDialog.Description class="text-sm text-neutral-600 dark:text-neutral-400">
                This action cannot be undone.
              </AlertDialog.Description>
            </div>
            <div class="flex justify-end gap-3">
              <AlertDialog.Close :class="buttonClasses">Cancel</AlertDialog.Close>
              <AlertDialog.Close :class="dangerButtonClasses"> Confirm </AlertDialog.Close>
            </div>
          </AlertDialog.Popup>
        </Transition>
      </AlertDialog.Portal>
    </template>
  </AlertDialog.Root>
</template>

Open from a menu ​

To open an alert dialog from a menu, bind the open state of the alert dialog with v-model:open. Set it to true in a click listener on the menu item. See Menu for the parts of the menu.

vue
<script setup lang="ts">
import { h, shallowRef } from 'vue';
import type { FunctionalComponent } from 'vue';
import { AlertDialog } from '@vase-ui/vue/alert-dialog';
import { Menu } from '@vase-ui/vue/menu';
import styles from './index.module.css';

const dialogOpen = shallowRef(false);
const backdropHiddenClass = styles.BackdropHidden;
const menuPopupHiddenClass = styles.MenuPopupHidden;
const dialogPopupHiddenClass = styles.DialogPopupHidden;

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );
</script>

<template>
  <Menu.Root>
    <Menu.Trigger :class="styles.Button">
      Playlist
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner :class="styles.Positioner" :side-offset="8" align="start">
        <Transition :enter-from-class="menuPopupHiddenClass" :leave-to-class="menuPopupHiddenClass">
          <Menu.Popup :class="styles.MenuPopup">
            <Menu.Item :class="styles.MenuItem">Play</Menu.Item>
            <Menu.Item :class="styles.MenuItem">Share</Menu.Item>
            <Menu.Separator :class="styles.Separator" />
            <Menu.Item :class="styles.MenuItem" @click="dialogOpen = true">Delete…</Menu.Item>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>

  <AlertDialog.Root v-model:open="dialogOpen">
    <AlertDialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <AlertDialog.Backdrop :class="styles.Backdrop" />
      </Transition>
      <Transition
        :enter-from-class="dialogPopupHiddenClass"
        :leave-to-class="dialogPopupHiddenClass"
      >
        <AlertDialog.Popup :class="styles.DialogPopup">
          <div :class="styles.Intro">
            <AlertDialog.Title :class="styles.Title">Delete playlist?</AlertDialog.Title>
            <AlertDialog.Description :class="styles.Description">
              You can't undo this action.
            </AlertDialog.Description>
          </div>
          <div :class="styles.Actions">
            <AlertDialog.Close :class="styles.Button">Cancel</AlertDialog.Close>
            <AlertDialog.Close data-color="red" :class="styles.Button">Delete</AlertDialog.Close>
          </div>
        </AlertDialog.Popup>
      </Transition>
    </AlertDialog.Portal>
  </AlertDialog.Root>
</template>
css
.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  &[data-color='red'] {
    color: oklch(50.5% 0.213 27.518deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.4% 0.191 22.216deg);
    }
  }

  @media (hover: hover) {
    &:hover:not(:disabled) {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active:not(:disabled) {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &[data-pressed] {
    background-color: oklch(97% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(26.9% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Positioner {
  outline: 0;
}

.MenuPopup {
  box-sizing: border-box;
  position: relative;
  outline: 0;
  padding-block: 0.25rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  background-color: white;
  color: oklch(14.5% 0 0deg);
  box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
  transform-origin: var(--transform-origin);
  transition:
    transform 100ms ease-out,
    opacity 100ms ease-out;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
    box-shadow: none;
  }
}

.MenuItem {
  outline: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 1rem;
  padding-right: 2rem;
  display: flex;
  font-size: 0.875rem;
  line-height: 1rem;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: white;

    @media (prefers-color-scheme: dark) {
      color: oklch(14.5% 0 0deg);
    }
  }

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: white;
    }
  }
}

.Separator {
  margin: 0.25rem;
  height: 1px;
  background-color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.Backdrop {
  position: fixed;
  inset: 0;
  background-color: black;
  opacity: 0.2;
  transition: opacity 150ms;

  /* iOS 26+: Ensure the backdrop covers the entire visible viewport. */
  @supports (-webkit-touch-callout: none) {
    position: absolute;
    min-height: 100dvh;
  }

  @media (prefers-color-scheme: dark) {
    opacity: 0.5;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the part. */
.BackdropHidden {
  opacity: 0;
}

.DialogPopup {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24rem;
  max-width: calc(100% - 3rem);
  margin-top: -2rem;
  padding: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  color: oklch(14.5% 0 0deg);
  box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
  transition:
    transform 100ms ease-out,
    opacity 100ms ease-out;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
    box-shadow: none;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the part. */
.DialogPopupHidden {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.98);
}

.Intro {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.Title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.5rem;
  font-weight: 700;
}

.Description {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(43.9% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: oklch(70.8% 0 0deg);
  }
}

.Actions {
  display: flex;
  justify-content: end;
  gap: 0.75rem;
}

/* The enter-from and leave-to class of the `<Transition>` around the part. */
.MenuPopupHidden {
  opacity: 0;
  transform: scale(0.98);
}
vue
<script setup lang="ts">
import { h, shallowRef } from 'vue';
import type { FunctionalComponent } from 'vue';
import { AlertDialog } from '@vase-ui/vue/alert-dialog';
import { Menu } from '@vase-ui/vue/menu';

const dialogOpen = shallowRef(false);
const backdropHiddenClass = 'opacity-0';
const menuPopupHiddenClass = 'scale-[0.98] opacity-0';
const dialogPopupHiddenClass = 'scale-[0.98] opacity-0';

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const buttonClass =
  'flex h-8 items-center justify-center gap-1.5 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 data-pressed:bg-neutral-100 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:data-pressed:bg-neutral-800 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white';

const itemClass =
  "flex cursor-default py-2 pr-8 pl-4 text-sm leading-4 outline-hidden select-none data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white";
</script>

<template>
  <Menu.Root>
    <Menu.Trigger :class="buttonClass">
      Playlist
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner class="outline-hidden" :side-offset="8" align="start">
        <Transition :enter-from-class="menuPopupHiddenClass" :leave-to-class="menuPopupHiddenClass">
          <Menu.Popup
            class="relative origin-[var(--transform-origin)] border border-neutral-950 bg-white py-1 text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-hidden transition-[scale,opacity] duration-100 ease-out dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
          >
            <Menu.Item :class="itemClass">Play</Menu.Item>
            <Menu.Item :class="itemClass">Share</Menu.Item>
            <Menu.Separator class="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />
            <Menu.Item :class="itemClass" @click="dialogOpen = true">Delete…</Menu.Item>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>

  <AlertDialog.Root v-model:open="dialogOpen">
    <AlertDialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <AlertDialog.Backdrop
          class="fixed inset-0 bg-black/20 dark:bg-black/50 transition-opacity duration-150 supports-[-webkit-touch-callout:none]:absolute supports-[-webkit-touch-callout:none]:min-h-dvh"
        />
      </Transition>
      <Transition
        :enter-from-class="dialogPopupHiddenClass"
        :leave-to-class="dialogPopupHiddenClass"
      >
        <AlertDialog.Popup
          class="fixed top-1/2 left-1/2 -mt-8 flex w-96 max-w-[calc(100%-3rem)] -translate-x-1/2 -translate-y-1/2 flex-col gap-4 bg-white dark:bg-neutral-950 p-4 text-neutral-950 dark:text-white border border-neutral-950 dark:border-white shadow-[0.25rem_0.25rem_0] shadow-black/12 dark:shadow-none transition-[scale,opacity] duration-100 ease-out"
        >
          <div class="flex flex-col gap-1">
            <AlertDialog.Title class="text-base font-bold">Delete playlist?</AlertDialog.Title>
            <AlertDialog.Description class="text-sm text-neutral-600 dark:text-neutral-400">
              You can't undo this action.
            </AlertDialog.Description>
          </div>
          <div class="flex justify-end gap-3">
            <AlertDialog.Close :class="buttonClass">Cancel</AlertDialog.Close>
            <AlertDialog.Close :class="[buttonClass, 'text-red-700 dark:text-red-400']"
              >Delete</AlertDialog.Close
            >
          </div>
        </AlertDialog.Popup>
      </Transition>
    </AlertDialog.Portal>
  </AlertDialog.Root>
</template>

API reference ​

AlertDialog.Root ​

Groups the parts of the alert dialog. The alert dialog is always modal. Escape and AlertDialog.Close close it, and a press outside the popup does not. Renders no element.

Props

PropTypeDefaultDescription
defaultOpenboolean | undefinedfalseThe dialog is open at the mount of an uncontrolled root.
defaultTriggerIdstring | null | undefinednullThe id of the active trigger at the mount, with defaultOpen.
handleAlertDialogHandle<Payload> | undefinedConnects the root to triggers outside it and to code. The type refuses a handle from Dialog.createHandle().
openboolean | undefinedThe dialog is open. v-model:open binds it.
triggerIdstring | null | undefinedThe id of the active trigger. v-model:trigger-id binds it.

Slots

SlotSlot propsDescription
default
payload: Payload | undefined
The content of the alert dialog. payload is the payload of the active trigger.

Events

EventArgumentsDescription
openChange[open: boolean, details: AlertDialogRootChangeEventDetails]The alert dialog opens or closes. details.cancel() keeps it as it was.
update:open[open: boolean]Comes after openChange, unless a listener cancels the change. v-model:open uses it.
update:triggerId[id: string | null]The active trigger changes. v-model:trigger-id uses it.

Exposed

MemberTypeDescription
close() => voidCloses the alert dialog with the reason 'imperative-action'.

AlertDialog.Trigger ​

A button that opens the alert dialog. Renders a <button> element.

Props

PropTypeDefaultDescription
disabledboolean | undefinedfalseThe user cannot press the trigger.
handleAlertDialogHandle<Payload> | undefinedConnects the trigger to a root outside it. The type refuses a handle from Dialog.createHandle().
idstring | undefinedThe root names the active trigger by this id in triggerId.
payloadPayload | undefinedThe payload that the alert dialog gets when this trigger opens it.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: AlertDialogTriggerState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: AlertDialogTriggerState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[aria-expanded="true"]The alert dialog is open for this trigger.
:disabledThe trigger is a native button, and it or a fieldset around it is disabled.
[aria-disabled="true"]The trigger is another element, and it is disabled.

AlertDialog.Portal ​

Moves its content to another place of the DOM, <body> by default. Renders no element.

Props

PropTypeDefaultDescription
deferboolean | undefinedfalseMoves the content after the other content of the same update mounted.
disabledboolean | undefinedfalseRenders the content in place, also on the server.
keepMountedboolean | undefinedfalseThe closed popup stays in the DOM, with hidden and inert.
toPortalTarget | undefinedThe target of the content. With no value, the target of the nearest portal above, else body. While it is null, the portal renders nothing.

Slots

SlotSlot propsDescription
defaultThe content of the part.

AlertDialog.Backdrop ​

An overlay under the popup. Renders a <div> element.

Props

PropTypeDefaultDescription
forceRenderboolean | undefinedfalseThe backdrop of a nested dialog renders its element.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: DialogBackdropState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: DialogBackdropState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[hidden]The alert dialog is closed, and keepMounted of the portal keeps the backdrop in the DOM.

AlertDialog.Viewport ​

A container that places the popup and scrolls it. Renders a <div> element.

Props

PropTypeDefaultDescription
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: DialogViewportState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: DialogViewportState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[hidden]The alert dialog is closed, and keepMounted of the portal keeps the viewport in the DOM.
[data-nested]The root of the alert dialog is inside a Dialog.Root, an AlertDialog.Root or a Drawer.Root.
[data-nested-dialog-open]A dialog, an alert dialog or a drawer is open above this alert dialog.
:has(> .v-leave-active)The popup leaves. Use the leave class of the <Transition> around the popup.

AlertDialog.Popup ​

The container of the content of the alert dialog, with the role alertdialog. Renders a <div> element.

Props

PropTypeDefaultDescription
finalFocusFocusTarget | undefinedThe element that gets the focus at the close, or false to keep the focus where it is. A function gets the type of the interaction and gives the element. By default: the trigger, else the element that had the focus before the open. After an open by code, that element comes before the trigger. For an element that is no tab stop, the focus goes to its first tab stop outside the popup. An element in the popup is no target.
idstring | undefinedThe trigger names the popup by this id in aria-controls.
initialFocusFocusTarget | undefinedThe element that gets the focus at the open, or false to move no focus. A function gets the type of the interaction and gives the element. By default: the element with autofocus, else the first tab stop, else the popup; after a touch, the popup. A modal dialog makes the page inert, so an element outside the popup cannot keep or get the focus.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: DialogPopupState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: DialogPopupState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[hidden]The alert dialog is closed, and keepMounted of the portal keeps the popup in the DOM.
[data-nested]The root of the alert dialog is inside a Dialog.Root, an AlertDialog.Root or a Drawer.Root.
[data-nested-dialog-open]A dialog, an alert dialog or a drawer is open above this alert dialog.

CSS variables

VariableDescription
--nested-dialogsThe number of dialogs, alert dialogs and drawers that are open above this alert dialog.

AlertDialog.Title ​

A heading that names the alert dialog. Renders an <h2> element.

Props

PropTypeDefaultDescription
idstring | undefinedThe popup names the title by this id in aria-labelledby.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: DialogTitleState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: DialogTitleState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

AlertDialog.Description ​

A paragraph that describes the alert dialog. Renders a <p> element.

Props

PropTypeDefaultDescription
idstring | undefinedThe popup names the description by this id in aria-describedby.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: DialogDescriptionState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: DialogDescriptionState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

AlertDialog.Close ​

A button that closes the alert dialog. Renders a <button> element.

Props

PropTypeDefaultDescription
disabledboolean | undefinedfalseThe user cannot press the button.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: DialogCloseState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: DialogCloseState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
:disabledThe button is a native button, and it or a fieldset around it is disabled.
[aria-disabled="true"]The button is another element, and it is disabled.

createHandle ​

Makes a handle that connects an AlertDialog.Root to AlertDialog.Trigger parts outside it.

Return value

AlertDialogHandle<Payload>

Handle ​

The class of the handle, which opens and closes the alert dialog from code.

Properties

PropertyTypeModifiersDescription
isOpenbooleanreadonlyThe popup is open. It is false while no root has the handle.

Methods

MethodReturnsDescription
open(triggerId: string | null)voidOpens the popup for the trigger with this id. With null, or with an id that no trigger of the root has, the popup opens with no trigger. A development build warns for such an id, and for a call with no mounted root.
openWithPayload(payload: Payload)voidOpens the popup with no trigger. The default slot of the root gets the payload until a trigger opens the popup. A development build warns for a call with no mounted root.
close()voidCloses the popup. With no mounted root, it does nothing.

Differences from Base UI ​

Vase UI ports Alert Dialog from Base UI 1.9.0.

API ​

Base UIVase UI
AlertDialog.Root prop onOpenChangeCompleteListen to @after-enter and @after-leave of the <Transition> around the popup. They run after its animations end.
AlertDialog.Root prop actionsRefA template ref of the root has close(). To keep the popup until a JavaScript animation ends, give :css="false" to the <Transition> around it, and call done in its leave hook.
AlertDialog.Trigger prop nativeButtonThe trigger reads its element to know if it is a native button, so it needs no nativeButton.
AlertDialog.Portal prop renderThe portal is a <Teleport> and renders no element, so it has no as and no element slot. Put an element in the portal when you need one.
AlertDialog.BackdropA <Transition> around the backdrop animates it, in place of data-starting-style, data-ending-style and the transitionStatus of the state. A closed backdrop leaves the DOM, or has [hidden] with keepMounted, so it needs no data-open and data-closed.
AlertDialog.ViewportThe viewport is new in the DOM at each open, so a CSS animation on it runs at the open. :has(> .v-leave-active) selects it while its popup leaves, and [hidden] while keepMounted keeps it closed. These take the place of data-starting-style, data-ending-style, data-open, data-closed and the transitionStatus of the state.
AlertDialog.PopupA <Transition> around the popup animates it, in place of data-starting-style, data-ending-style and the transitionStatus of the state. A closed popup leaves the DOM, or has [hidden] with keepMounted, so it needs no data-open and data-closed.
AlertDialog.Close prop nativeButtonThe button reads its element to know if it is a native button, so it needs no nativeButton.

Added in Vase UI ​

PartMemberWhy
AlertDialog.Portaldisabled propThe portal is a <Teleport>. With disabled, it renders its content in place, also in the server HTML.
AlertDialog.Portaldefer propThe portal is a <Teleport>. With defer, it moves its content after the rest of the update mounts, so its target can come later in the same template.
AlertDialog.Rootupdate:triggerId eventv-model:trigger-id binds the active trigger, as v-model:open binds the open state.

Return types ​

FunctionVase UI returnsWhy
AlertDialog.createHandleAlertDialogHandle<Payload>The return type names the class AlertDialogHandle, which the namespace exports as AlertDialog.Handle.

Behavior ​

Vase UIEvidence
While a modal dialog or a modal drawer is open, each element outside it is inert, the trigger too, as with showModal() of a native <dialog>. An inert element cannot keep or take the focus. So with initialFocus of false, or a function that returns nothing, the dialog moves no focus into the popup, the trigger does not keep the focus, and Tab goes to the first tab stop of the dialog. An element outside a modal popup that initialFocus names takes no focus for the same reason. A dialog with modal of 'trap-focus' or false keeps its trigger in use, and there the focus stays on the trigger. Base UI leaves the focus on the trigger of a modal dialog and gives it to an outside element that initialFocus names, while it hides those elements from assistive technology.
close() of a handle with no mounted root does nothing and gives no warning: the popup is closed, which is what the call asks for. When two mounted roots have one handle, the root that mounted last has the handle, and the other root gets it back when that root unmounts; the library gives no warning. Base UI warns in a development build in both cases.
A button part knows the element of a component in as or of the element slot only at the mount, and it needs no prop that says what the element is. Until the mount, the element has the attributes that suit a <button> and each other element: type="button", role="button", a tab stop, and the disabled state of both. So in the server HTML, Tab reaches a <div> before a lazy hydration, and a <button> does not submit its form. At the mount, the part keeps the attributes of its element. Base UI needs nativeButton set to false for an element that is not a <button>.

The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.