Skip to content

Dialog ​

A popup that opens on top of the entire page.

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

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

<template>
  <Dialog.Root>
    <Dialog.Trigger :class="styles.Button">View notifications</Dialog.Trigger>
    <Dialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <Dialog.Backdrop :class="styles.Backdrop" />
      </Transition>
      <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
        <Dialog.Popup :class="styles.Popup">
          <div :class="styles.Intro">
            <Dialog.Title :class="styles.Title">Notifications</Dialog.Title>
            <Dialog.Description :class="styles.Description">
              You are all caught up. Good job!
            </Dialog.Description>
          </div>
          <div :class="styles.Actions">
            <Dialog.Close :class="styles.Button">Close</Dialog.Close>
          </div>
        </Dialog.Popup>
      </Transition>
    </Dialog.Portal>
  </Dialog.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);
    }
  }

  &: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);
    }
  }

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

    @media (prefers-color-scheme: dark) {
      outline-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;
}

.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 { Dialog } from '@vase-ui/vue/dialog';

const backdropHiddenClass = 'opacity-0';
const popupHiddenClass = 'scale-[0.98] opacity-0';
</script>

<template>
  <Dialog.Root>
    <Dialog.Trigger
      class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
      >View notifications</Dialog.Trigger
    >
    <Dialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <Dialog.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">
        <Dialog.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">
            <Dialog.Title class="text-base font-bold">Notifications</Dialog.Title>
            <Dialog.Description class="text-sm text-neutral-600 dark:text-neutral-400">
              You are all caught up. Good job!
            </Dialog.Description>
          </div>
          <div class="flex justify-end gap-3">
            <Dialog.Close
              class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
              >Close</Dialog.Close
            >
          </div>
        </Dialog.Popup>
      </Transition>
    </Dialog.Portal>
  </Dialog.Root>
</template>

Usage guidelines ​

  • Dialog does not support gestures: Use Drawer for gestures or snap points. A panel that slides in from the edge of the screen and needs no gestures is a Dialog with a position.

Anatomy ​

Import the component and assemble its parts:

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

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

Examples ​

State ​

By default, Dialog is an uncontrolled component that keeps its own state.

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

<template>
  <Dialog.Root>
    <Dialog.Trigger>Open</Dialog.Trigger>
    <Dialog.Portal>
      <Dialog.Popup>
        <Dialog.Title>Example dialog</Dialog.Title>
        <Dialog.Close>Close</Dialog.Close>
      </Dialog.Popup>
    </Dialog.Portal>
  </Dialog.Root>
</template>

To read or control the open state, bind it with v-model:open. You can then open the dialog from another place in your app. This dialog closes when the user submits its form:

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

declare function submitData(): Promise<void>;

const open = shallowRef(false);

// Close the dialog once the form data is submitted
async function handleSubmit() {
  await submitData();
  open.value = false;
}
</script>

<template>
  <Dialog.Root v-model:open="open">
    <Dialog.Trigger>Open</Dialog.Trigger>
    <Dialog.Portal>
      <Dialog.Popup>
        <form @submit.prevent="handleSubmit">
          <!-- ... -->
        </form>
      </Dialog.Popup>
    </Dialog.Portal>
  </Dialog.Root>
</template>

To run code when the dialog opens or closes, listen to the openChange event of Dialog.Root:

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

declare function doStuff(): void;

const open = shallowRef(false);

function handleOpenChange(nextOpen: boolean) {
  // Do stuff when the dialog is closed
  if (!nextOpen) {
    doStuff();
  }
  // Set the new state
  open.value = nextOpen;
}
</script>

<template>
  <Dialog.Root :open="open" @open-change="handleOpenChange">
    <!-- ... -->
  </Dialog.Root>
</template>

Nested dialogs ​

You can put a dialog in another dialog.

To style the parent dialog while a nested dialog is open, use the [data-nested-dialog-open] selector and the --nested-dialogs CSS variable. A nested dialog renders no backdrop unless its backdrop has forceRender, so the parent dialog stays clear behind the dialog on top of it.

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

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

<template>
  <Dialog.Root>
    <Dialog.Trigger :class="styles.Button">View notifications</Dialog.Trigger>
    <Dialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <Dialog.Backdrop :class="styles.Backdrop" />
      </Transition>
      <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
        <Dialog.Popup :class="styles.Popup">
          <div :class="styles.Intro">
            <Dialog.Title :class="styles.Title">Notifications</Dialog.Title>
            <Dialog.Description :class="styles.Description">
              You are all caught up. Good job!
            </Dialog.Description>
          </div>
          <div :class="styles.Actions">
            <Dialog.Root>
              <Dialog.Trigger :class="styles.Button">Customize</Dialog.Trigger>
              <Dialog.Portal>
                <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
                  <Dialog.Popup :class="styles.Popup">
                    <div :class="styles.Intro">
                      <Dialog.Title :class="styles.Title">Customize notifications</Dialog.Title>
                      <Dialog.Description :class="styles.Description">
                        Review your settings here.
                      </Dialog.Description>
                    </div>
                    <div :class="styles.EndActions">
                      <Dialog.Close :class="styles.Button">Close</Dialog.Close>
                    </div>
                  </Dialog.Popup>
                </Transition>
              </Dialog.Portal>
            </Dialog.Root>
          </div>
        </Dialog.Popup>
      </Transition>
    </Dialog.Portal>
  </Dialog.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);
    }
  }

  &: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);
    }
  }

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

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

.GhostButton {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  border: none;
  background-color: transparent;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.25rem;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

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

  @media (hover: hover) {
    &:hover {
      background-color: oklch(92.2% 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;
    }
  }
}

.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;
  position: fixed;
  top: 50%;
  left: 50%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  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%);
  translate: -50% calc(-50% + 1.25rem * var(--nested-dialogs));
  scale: calc(1 - 0.1 * var(--nested-dialogs));
  transition:
    translate 100ms ease-out,
    scale 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;
  }

  &::after {
    content: '';
    position: absolute;
    inset: 0;
    background-color: rgb(0 0 0 / 0.05);
    opacity: 0;
    pointer-events: none;
    transition: opacity 100ms ease-out;
  }

  &[data-nested-dialog-open]::after {
    opacity: 1;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the part. */
.PopupHidden {
  opacity: 0;
  translate: -50% calc(-50% + 0.25rem + 1.25rem * var(--nested-dialogs));
  scale: 0.96;
}

.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;
  align-items: center;
  gap: 0.75rem;
}

.EndActions {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 0.75rem;
}
vue
<script setup lang="ts">
import { Dialog } from '@vase-ui/vue/dialog';

const backdropHiddenClass = 'opacity-0';
const popupHiddenClass =
  'top-[calc(50%+0.25rem+1.25rem*var(--nested-dialogs))]! scale-[0.96]! opacity-0';
</script>

<template>
  <Dialog.Root>
    <Dialog.Trigger
      class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
      >View notifications</Dialog.Trigger
    >
    <Dialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <Dialog.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">
        <Dialog.Popup
          class="fixed top-[calc(50%+1.25rem*var(--nested-dialogs))] 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 scale-[calc(1-0.1*var(--nested-dialogs))] 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-[top,scale,opacity] duration-100 ease-out after:absolute after:inset-0 after:bg-black/5 after:opacity-0 after:transition-opacity after:duration-100 after:ease-out after:pointer-events-none data-nested-dialog-open:after:opacity-100"
        >
          <div class="flex flex-col gap-1">
            <Dialog.Title class="text-base font-bold">Notifications</Dialog.Title>
            <Dialog.Description class="text-sm text-neutral-600 dark:text-neutral-400">
              You are all caught up. Good job!
            </Dialog.Description>
          </div>
          <div class="flex items-center gap-3">
            <Dialog.Root>
              <Dialog.Trigger
                class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
                >Customize</Dialog.Trigger
              >
              <Dialog.Portal>
                <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
                  <Dialog.Popup
                    class="fixed top-[calc(50%+1.25rem*var(--nested-dialogs))] 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 scale-[calc(1-0.1*var(--nested-dialogs))] 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-[top,scale,opacity] duration-100 ease-out after:absolute after:inset-0 after:bg-black/5 after:opacity-0 after:transition-opacity after:duration-100 after:ease-out after:pointer-events-none data-nested-dialog-open:after:opacity-100"
                  >
                    <div class="flex flex-col gap-1">
                      <Dialog.Title class="text-base font-bold"
                        >Customize notifications</Dialog.Title
                      >
                      <Dialog.Description class="text-sm text-neutral-600 dark:text-neutral-400">
                        Review your settings here.
                      </Dialog.Description>
                    </div>
                    <div class="flex items-center justify-end gap-3">
                      <Dialog.Close
                        class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
                        >Close</Dialog.Close
                      >
                    </div>
                  </Dialog.Popup>
                </Transition>
              </Dialog.Portal>
            </Dialog.Root>
          </div>
        </Dialog.Popup>
      </Transition>
    </Dialog.Portal>
  </Dialog.Root>
</template>

Custom focus management ​

The initialFocus and finalFocus props of Dialog.Popup set the element that gets the focus when the dialog opens and when it closes.

Set a prop to false to move no focus. Or give a function that gets the type of the interaction and returns the element to focus. A modal dialog makes the rest of the page inert, so an element outside the popup cannot keep or get the focus at the open.

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

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

const initialFocusRef = useTemplateRef<HTMLInputElement>('initialFocus');
const finalFocusRef = useTemplateRef<HTMLButtonElement>('finalFocus');
const nameId = useId();
const feedbackId = useId();
</script>

<template>
  <div :class="styles.Container">
    <Dialog.Root>
      <Dialog.Trigger :class="styles.Button">Open feedback</Dialog.Trigger>
      <Dialog.Portal>
        <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
          <Dialog.Backdrop :class="styles.Backdrop" />
        </Transition>
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Dialog.Popup
            :class="styles.Popup"
            :initial-focus="initialFocusRef"
            :final-focus="finalFocusRef"
          >
            <div :class="styles.Intro">
              <Dialog.Title :class="styles.Title">Feedback form</Dialog.Title>
              <Dialog.Description :class="styles.Description">
                Your feedback means a lot to us.
              </Dialog.Description>
            </div>
            <div :class="styles.Fields">
              <div :class="styles.Field">
                <label :for="nameId" :class="styles.Label">Full name</label>
                <input :id="nameId" placeholder="Enter your name" :class="styles.Input" />
              </div>
              <div :class="styles.Field">
                <label :for="feedbackId" :class="styles.Label">Feedback</label>
                <input
                  :id="feedbackId"
                  ref="initialFocus"
                  required
                  placeholder="Enter your feedback"
                  :class="styles.Input"
                />
              </div>
            </div>
            <div :class="styles.Actions">
              <Dialog.Close :class="styles.Button">Close</Dialog.Close>
            </div>
          </Dialog.Popup>
        </Transition>
      </Dialog.Portal>
    </Dialog.Root>
    <button ref="finalFocus" type="button" :class="styles.Button">Final focus</button>
  </div>
</template>
css
.Container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}

.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);
    }
  }

  &: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);
    }
  }

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

    @media (prefers-color-scheme: dark) {
      outline-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;
}

.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,
.Fields,
.Field {
  display: flex;
  flex-direction: column;
}

.Intro {
  gap: 0.25rem;
}

.Fields {
  gap: 0.75rem;
}

.Field {
  align-items: start;
  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);
  }
}

.Label {
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 400;
}

.Input {
  box-sizing: border-box;
  padding: 0 0.5rem;
  margin: 0;
  border-radius: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  width: 100%;
  height: 2rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  background-color: white;
  color: oklch(14.5% 0 0deg);

  @media (any-pointer: coarse) {
    font-size: 1rem;
  }

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

  &::placeholder {
    color: oklch(55.6% 0 0deg);

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

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

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

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

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

const initialFocusRef = useTemplateRef<HTMLInputElement>('initialFocus');
const finalFocusRef = useTemplateRef<HTMLButtonElement>('finalFocus');
const nameId = useId();
const feedbackId = useId();
</script>

<template>
  <div class="flex flex-wrap justify-center gap-3">
    <Dialog.Root>
      <Dialog.Trigger
        class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
        >Open feedback</Dialog.Trigger
      >
      <Dialog.Portal>
        <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
          <Dialog.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">
          <Dialog.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"
            :initial-focus="initialFocusRef"
            :final-focus="finalFocusRef"
          >
            <div class="flex flex-col gap-1">
              <Dialog.Title class="text-base font-bold">Feedback form</Dialog.Title>
              <Dialog.Description class="text-sm text-neutral-600 dark:text-neutral-400">
                Your feedback means a lot to us.
              </Dialog.Description>
            </div>
            <div class="flex flex-col gap-3">
              <div class="flex flex-col items-start gap-1">
                <label :for="nameId" class="text-sm font-normal">Full name</label>
                <input
                  :id="nameId"
                  placeholder="Enter your name"
                  class="h-8 w-full border border-neutral-950 dark:border-white bg-white dark:bg-neutral-950 px-2 text-sm any-pointer-coarse:text-base font-normal text-neutral-950 dark:text-white placeholder:text-neutral-500 dark:placeholder:text-neutral-400 focus:outline-2 focus:-outline-offset-1 focus:outline-neutral-950 dark:focus:outline-white"
                />
              </div>
              <div class="flex flex-col items-start gap-1">
                <label :for="feedbackId" class="text-sm font-normal">Feedback</label>
                <input
                  :id="feedbackId"
                  ref="initialFocus"
                  required
                  placeholder="Enter your feedback"
                  class="h-8 w-full border border-neutral-950 dark:border-white bg-white dark:bg-neutral-950 px-2 text-sm any-pointer-coarse:text-base font-normal text-neutral-950 dark:text-white placeholder:text-neutral-500 dark:placeholder:text-neutral-400 focus:outline-2 focus:-outline-offset-1 focus:outline-neutral-950 dark:focus:outline-white"
                />
              </div>
            </div>
            <div class="flex justify-end gap-3">
              <Dialog.Close
                class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
                >Close</Dialog.Close
              >
            </div>
          </Dialog.Popup>
        </Transition>
      </Dialog.Portal>
    </Dialog.Root>
    <button
      ref="finalFocus"
      type="button"
      class="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:bg-neutral-100 dark:hover:bg-neutral-800 active:bg-neutral-200 dark:active:bg-neutral-700 disabled:border-neutral-500 disabled:text-neutral-500 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
    >
      Final focus
    </button>
  </div>
</template>

Outside scroll dialog ​

To make the dialog scroll, use Dialog.Viewport as an outer container of Dialog.Popup that scrolls. The popup can then go past the bottom edge of the screen.

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

const backdropHiddenClass = styles.BackdropHidden;
const backdropLeaveActiveClass = styles.BackdropLeaveActive;
const popupEnterFromClass = styles.PopupEnterFrom;
const popupLeaveToClass = styles.PopupLeaveTo;
const popupLeaveActiveClass = styles.PopupLeaveActive;

const popupRef = useTemplateRef('popup');

const XIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      style: { display: 'block' },
    },
    [h('path', { d: 'm2.5 2.5 11 11m-11 0 11-11' })],
  );

const CONTENT_SECTIONS = [
  {
    title: 'What a dialog is for',
    body: 'Use a dialog when you need the user to complete a focused task or read something important without navigating away. It opens on top of the page and returns focus back where it started when closed.',
  },
  {
    title: 'Anatomy at a glance',
    body: 'Root, Trigger, Portal, Backdrop, Viewport, Popup, Title, Description, Close. Keep the title short and the first paragraph specific so screen readers announce something meaningful.',
  },
  {
    title: 'Opening and closing',
    body: 'Control it using external state via `v-model:open`, or let it manage state for you internally.',
  },
  {
    title: 'Keyboard and focus behavior',
    body: 'Focus moves inside the dialog when it opens. Tab and Shift+Tab loop within, and Esc requests close.',
  },
  {
    title: 'Accessible labeling',
    body: 'Set an explicit title and description using the `Dialog.Title` and `Dialog.Description` components.',
  },
  {
    title: 'Backdrop and page scrolling',
    body: 'The backdrop visually separates layers while background content is inert. Don’t rely on dimness alone—keep copy clear and buttons obvious so actions are easy to choose.',
  },
  {
    title: 'Portals and stacking',
    body: 'Dialogs render in a portal so they sit above the `isolation: isolate` app content and avoid local z-index wars.',
  },
  {
    title: 'Viewport overflow',
    body: 'Let long content overflow the bottom edge and reveal as you scroll the page container. Keep generous padding at the top and bottom so the dialog doesn’t feel jammed against the edges.',
  },
  {
    title: 'Nested dialogs and confirmations',
    body: 'If closing a dialog needs confirmation, open a child alert dialog rather than mutating the current one. The parent stays visible behind it; only the topmost layer should feel interactive.',
  },
  {
    title: 'Transitions that respect motion settings',
    body: 'Use small, fast transitions (opacity plus a few pixels of Y translation or scale). Subtle motion helps people notice what changed without slowing them down.',
  },
  {
    title: 'Controlled vs. uncontrolled',
    body: 'Controlled state is best when other parts of the page need to react to open/close. Uncontrolled is fine for local cases where only the dialog matters.',
  },
  {
    title: 'Close affordances',
    body: 'Always offer a visible close button in the corner. Don’t rely only on Esc or the backdrop for pointer outside presses. Touch screen readers and accessibility users benefit from a clear, targetable control to click to close the dialog.',
  },
  {
    title: 'Forms inside dialogs',
    body: 'Keep forms short; longer flows usually deserve a full page. Validate inline, keep button text specific (“Create project”), and disable destructive actions until the input is valid.',
  },
  {
    title: 'Content guidelines',
    body: 'Lead with the outcome (“Rename project?”) and follow with one or two short, concrete sentences. Avoid long prose; link out for details instead.',
  },
  {
    title: 'SSR and hydration notes',
    body: 'Because dialogs render in a portal, make sure your portal container exists on the client.',
  },
  {
    title: 'Mobile ergonomics',
    body: 'Use larger touch targets and keep the close button reachable with the thumb. Avoid full-screen modals unless the task truly needs a whole screen.',
  },
  {
    title: 'Theming and density',
    body: 'Match spacing and corner radius to your system. Use a slightly denser layout than pages so the dialog feels purpose-built, not like a mini web page.',
  },
  {
    title: 'Internationalization',
    body: 'Plan for longer text. Buttons can grow to two lines; titles should wrap gracefully. Keep destructive terms consistent across locales.',
  },
  {
    title: 'Performance',
    body: 'Children are mounted lazily when the dialog opens. If the dialog can reopen often, consider the `keepMounted` prop sparingly to perform the work only once on mount to avoid re-initializing complex component trees on each open.',
  },
  {
    title: 'When a popover is better',
    body: 'If the content is a small hint or a few quick actions anchored to a control, use a popover or menu instead of a dialog. Dialogs interrupt on purpose—use that sparingly.',
  },
  {
    title: 'Follow-up and cleanup',
    body: 'After a successful action, close the dialog and show confirmation in context (toast, inline message, or updated UI) so people can see the result of what they just did.',
  },
];

const base = import.meta.env.BASE_URL;

const RELATED_LINKS = [
  { href: `${base}components/scroll-area`, label: 'Scroll Area' },
  { href: `${base}components/drawer`, label: 'Drawer' },
  { href: `${base}components/popover`, label: 'Popover' },
] as const;
</script>

<template>
  <Dialog.Root>
    <Dialog.Trigger :class="styles.Button">Open dialog</Dialog.Trigger>
    <Dialog.Portal>
      <Transition
        :enter-from-class="backdropHiddenClass"
        :leave-to-class="backdropHiddenClass"
        :leave-active-class="backdropLeaveActiveClass"
      >
        <Dialog.Backdrop :class="styles.Backdrop" />
      </Transition>
      <Dialog.Viewport :class="styles.Viewport">
        <div :class="styles.ScrollContent">
          <Transition
            :enter-from-class="popupEnterFromClass"
            :leave-to-class="popupLeaveToClass"
            :leave-active-class="popupLeaveActiveClass"
          >
            <Dialog.Popup ref="popup" :class="styles.Popup" :initial-focus="popupRef?.element">
              <div :class="styles.PopupHeader">
                <Dialog.Title :class="styles.Title">Dialog</Dialog.Title>
                <Dialog.Description :class="styles.Description">
                  This layout keeps an outer container scrollable while the dialog can extend past
                  the bottom edge.
                </Dialog.Description>
                <Dialog.Close :class="styles.Close" aria-label="Close">
                  <XIcon />
                </Dialog.Close>
              </div>

              <div :class="styles.Body">
                <section v-for="item in CONTENT_SECTIONS" :key="item.title" :class="styles.Section">
                  <h3 :class="styles.SectionTitle">{{ item.title }}</h3>
                  <p :class="styles.SectionBody">{{ item.body }}</p>
                </section>
              </div>

              <p :class="styles.FooterNote">
                Related docs:
                <template v-for="(item, index) in RELATED_LINKS" :key="item.href"
                  >{{ index > 0 ? ', ' : ''
                  }}<a :class="styles.FooterLink" :href="item.href">{{ item.label }}</a></template
                >.
              </p>
            </Dialog.Popup>
          </Transition>
        </div>
      </Dialog.Viewport>
    </Dialog.Portal>
  </Dialog.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);
    }
  }

  &: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);
    }
  }

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

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

.Backdrop {
  position: fixed;
  inset: 0;
  background-color: rgb(0 0 0 / 20%);
  transition-duration: 600ms;
  transition-property: opacity;
  transition-timing-function: var(--ease-out-fast);

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

  @media (prefers-color-scheme: dark) {
    background-color: rgb(0 0 0 / 50%);
  }
}

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

/* The leave-active class of the `<Transition>` around the part. */
.BackdropLeaveActive {
  transition-duration: 350ms;
  transition-timing-function: cubic-bezier(0.375, 0.015, 0.545, 0.455);
}

.Viewport {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.ScrollContent {
  display: flex;
  align-items: center;
  min-height: 100%;
  /* Keeps the popup's enter and exit transforms from resizing the scroll area */
  overflow: clip;
}

.Popup {
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: min(40rem, calc(100vw - 2rem));
  padding: 1rem;
  margin: 4rem auto;
  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 700ms cubic-bezier(0.45, 1.005, 0, 1.005);
  outline: 0;

  @media (prefers-reduced-motion: reduce) {
    transition: none;
  }

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

/* The enter-from class of the `<Transition>` around the part. */
.PopupEnterFrom {
  transform: translateY(100dvh);
}

/* The leave-to class of the `<Transition>` around the part. */
.PopupLeaveTo {
  transform: translateY(max(100dvh, 100%));
}

/* The leave-active class of the `<Transition>` around the part. */
.PopupLeaveActive {
  transition-duration: 350ms;
  transition-timing-function: cubic-bezier(0.375, 0.015, 0.545, 0.455);
}

.PopupHeader {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-right: 2rem;
}

.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);
  }
}

.Close {
  box-sizing: border-box;
  position: absolute;
  top: -0.25rem;
  right: -0.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  background-color: transparent;
  color: oklch(14.5% 0 0deg);

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

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

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

  &:active {
    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;
    }
  }
}

.Body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.Section {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.SectionTitle {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 700;
}

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

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

.FooterNote {
  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);
  }
}

.FooterLink {
  color: oklch(14.5% 0 0deg);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;

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

  @media (hover: hover) {
    &:hover {
      text-decoration: none;
    }
  }

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

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
vue
<script setup lang="ts">
import { h, useTemplateRef } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Dialog } from '@vase-ui/vue/dialog';

const backdropHiddenClass = 'opacity-0';
const backdropLeaveActiveClass = 'duration-[350ms]! ease-[cubic-bezier(0.375,0.015,0.545,0.455)]!';
const popupEnterFromClass = 'translate-y-[100dvh]';
const popupLeaveToClass = 'translate-y-[max(100dvh,100%)]';
const popupLeaveActiveClass = 'duration-[350ms]! ease-[cubic-bezier(0.375,0.015,0.545,0.455)]!';

const popupRef = useTemplateRef('popup');

const XIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      style: { display: 'block' },
    },
    [h('path', { d: 'm2.5 2.5 11 11m-11 0 11-11' })],
  );

const CONTENT_SECTIONS = [
  {
    title: 'What a dialog is for',
    body: 'Use a dialog when you need the user to complete a focused task or read something important without navigating away. It opens on top of the page and returns focus back where it started when closed.',
  },
  {
    title: 'Anatomy at a glance',
    body: 'Root, Trigger, Portal, Backdrop, Viewport, Popup, Title, Description, Close. Keep the title short and the first paragraph specific so screen readers announce something meaningful.',
  },
  {
    title: 'Opening and closing',
    body: 'Control it using external state via `v-model:open`, or let it manage state for you internally.',
  },
  {
    title: 'Keyboard and focus behavior',
    body: 'Focus moves inside the dialog when it opens. Tab and Shift+Tab loop within, and Esc requests close.',
  },
  {
    title: 'Accessible labeling',
    body: 'Set an explicit title and description using the `Dialog.Title` and `Dialog.Description` components.',
  },
  {
    title: 'Backdrop and page scrolling',
    body: 'The backdrop visually separates layers while background content is inert. Don’t rely on dimness alone—keep copy clear and buttons obvious so actions are easy to choose.',
  },
  {
    title: 'Portals and stacking',
    body: 'Dialogs render in a portal so they sit above the `isolation: isolate` app content and avoid local z-index wars.',
  },
  {
    title: 'Viewport overflow',
    body: 'Let long content overflow the bottom edge and reveal as you scroll the page container. Keep generous padding at the top and bottom so the dialog doesn’t feel jammed against the edges.',
  },
  {
    title: 'Nested dialogs and confirmations',
    body: 'If closing a dialog needs confirmation, open a child alert dialog rather than mutating the current one. The parent stays visible behind it; only the topmost layer should feel interactive.',
  },
  {
    title: 'Transitions that respect motion settings',
    body: 'Use small, fast transitions (opacity plus a few pixels of Y translation or scale). Subtle motion helps people notice what changed without slowing them down.',
  },
  {
    title: 'Controlled vs. uncontrolled',
    body: 'Controlled state is best when other parts of the page need to react to open/close. Uncontrolled is fine for local cases where only the dialog matters.',
  },
  {
    title: 'Close affordances',
    body: 'Always offer a visible close button in the corner. Don’t rely only on Esc or the backdrop for pointer outside presses. Touch screen readers and accessibility users benefit from a clear, targetable control to click to close the dialog.',
  },
  {
    title: 'Forms inside dialogs',
    body: 'Keep forms short; longer flows usually deserve a full page. Validate inline, keep button text specific (“Create project”), and disable destructive actions until the input is valid.',
  },
  {
    title: 'Content guidelines',
    body: 'Lead with the outcome (“Rename project?”) and follow with one or two short, concrete sentences. Avoid long prose; link out for details instead.',
  },
  {
    title: 'SSR and hydration notes',
    body: 'Because dialogs render in a portal, make sure your portal container exists on the client.',
  },
  {
    title: 'Mobile ergonomics',
    body: 'Use larger touch targets and keep the close button reachable with the thumb. Avoid full-screen modals unless the task truly needs a whole screen.',
  },
  {
    title: 'Theming and density',
    body: 'Match spacing and corner radius to your system. Use a slightly denser layout than pages so the dialog feels purpose-built, not like a mini web page.',
  },
  {
    title: 'Internationalization',
    body: 'Plan for longer text. Buttons can grow to two lines; titles should wrap gracefully. Keep destructive terms consistent across locales.',
  },
  {
    title: 'Performance',
    body: 'Children are mounted lazily when the dialog opens. If the dialog can reopen often, consider the `keepMounted` prop sparingly to perform the work only once on mount to avoid re-initializing complex component trees on each open.',
  },
  {
    title: 'When a popover is better',
    body: 'If the content is a small hint or a few quick actions anchored to a control, use a popover or menu instead of a dialog. Dialogs interrupt on purpose—use that sparingly.',
  },
  {
    title: 'Follow-up and cleanup',
    body: 'After a successful action, close the dialog and show confirmation in context (toast, inline message, or updated UI) so people can see the result of what they just did.',
  },
];

const base = import.meta.env.BASE_URL;

const RELATED_LINKS = [
  { href: `${base}components/scroll-area`, label: 'Scroll Area' },
  { href: `${base}components/drawer`, label: 'Drawer' },
  { href: `${base}components/popover`, label: 'Popover' },
] as const;
</script>

<template>
  <Dialog.Root>
    <Dialog.Trigger
      class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
      >Open dialog</Dialog.Trigger
    >
    <Dialog.Portal>
      <Transition
        :enter-from-class="backdropHiddenClass"
        :leave-to-class="backdropHiddenClass"
        :leave-active-class="backdropLeaveActiveClass"
      >
        <Dialog.Backdrop
          class="fixed inset-0 bg-black/20 dark:bg-black/50 transition-opacity duration-[600ms] ease-[var(--ease-out-fast)] supports-[-webkit-touch-callout:none]:absolute"
        />
      </Transition>
      <Dialog.Viewport class="fixed inset-0 overflow-y-auto overscroll-contain">
        <div class="flex min-h-full items-center overflow-clip">
          <Transition
            :enter-from-class="popupEnterFromClass"
            :leave-to-class="popupLeaveToClass"
            :leave-active-class="popupLeaveActiveClass"
          >
            <Dialog.Popup
              ref="popup"
              class="outline-0 relative mx-auto my-16 flex w-[min(40rem,calc(100vw-2rem))] 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-[translate] duration-[700ms] ease-[cubic-bezier(0.45,1.005,0,1.005)] motion-reduce:transition-none"
              :initial-focus="popupRef?.element"
            >
              <div class="relative flex flex-col gap-1 pr-8">
                <Dialog.Title class="text-base font-bold">Dialog</Dialog.Title>
                <Dialog.Description class="text-sm text-neutral-600 dark:text-neutral-400">
                  This layout keeps an outer container scrollable while the dialog can extend past
                  the bottom edge.
                </Dialog.Description>
                <Dialog.Close
                  class="absolute -top-1 -right-1 inline-flex items-center justify-center w-8 h-8 border-none bg-transparent p-0 text-neutral-950 dark:text-white hover:bg-neutral-100 dark:hover:bg-neutral-800 active:bg-neutral-200 dark:active:bg-neutral-700 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
                  aria-label="Close"
                >
                  <XIcon />
                </Dialog.Close>
              </div>

              <div class="flex flex-col gap-4">
                <section
                  v-for="item in CONTENT_SECTIONS"
                  :key="item.title"
                  class="flex flex-col gap-1"
                >
                  <h3 class="text-sm font-bold">{{ item.title }}</h3>
                  <p class="text-sm text-neutral-700 dark:text-neutral-300">{{ item.body }}</p>
                </section>
              </div>

              <p class="text-sm text-neutral-600 dark:text-neutral-400">
                Related docs:
                <template v-for="(item, index) in RELATED_LINKS" :key="item.href"
                  >{{ index > 0 ? ', ' : ''
                  }}<a
                    class="text-neutral-950 dark:text-white underline underline-offset-[0.16em] decoration-[1px] hover:no-underline focus-visible:outline-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white focus-visible:outline-offset-2"
                    :href="item.href"
                    >{{ item.label }}</a
                  ></template
                >.
              </p>
            </Dialog.Popup>
          </Transition>
        </div>
      </Dialog.Viewport>
    </Dialog.Portal>
  </Dialog.Root>
</template>

Inside scroll dialog ​

To keep the popup fully on the screen, make a container in the popup scroll. Dialog.Viewport then sets the position of Dialog.Popup.

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

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

const CONTENT_SECTIONS = [
  {
    title: 'What a dialog is for',
    body: 'Use a dialog when you need the user to complete a focused task or read something important without navigating away. It opens on top of the page and returns focus back where it started when closed.',
  },
  {
    title: 'Anatomy at a glance',
    body: 'Root, Trigger, Portal, Backdrop, Popup, Title/Description, Close. Keep the title short and the first paragraph specific so screen readers announce something meaningful.',
  },
  {
    title: 'Opening and closing',
    body: 'Control it using external state via `v-model:open`, or let it manage state for you internally.',
  },
  {
    title: 'Keyboard and focus behavior',
    body: 'Focus moves inside the dialog when it opens. Tab and Shift+Tab loop within, and Esc requests close.',
  },
  {
    title: 'Accessible labeling',
    body: 'Set an explicit title and description using the `Dialog.Title` and `Dialog.Description` components.',
  },
  {
    title: 'Backdrop and page scrolling',
    body: 'The backdrop visually separates layers while background content is inert. Don’t rely on dimness alone—keep copy clear and buttons obvious so actions are easy to choose.',
  },
  {
    title: 'Portals and stacking',
    body: 'Dialogs render in a portal so they sit above the `isolation: isolate` app content and avoid local z-index wars.',
  },
  {
    title: 'Viewport overflow',
    body: 'Let long content overflow the bottom edge and reveal as you scroll the page container. Keep generous padding at the top and bottom so the dialog doesn’t feel jammed against the edges.',
  },
  {
    title: 'Nested dialogs and confirmations',
    body: 'If closing a dialog needs confirmation, open a child alert dialog rather than mutating the current one. The parent stays visible behind it; only the topmost layer should feel interactive.',
  },
  {
    title: 'Transitions that respect motion settings',
    body: 'Use small, fast transitions (opacity plus a few pixels of Y translation or scale). Subtle motion helps people notice what changed without slowing them down.',
  },
  {
    title: 'Controlled vs. uncontrolled',
    body: 'Controlled state is best when other parts of the page need to react to open/close. Uncontrolled is fine for local cases where only the dialog matters.',
  },
  {
    title: 'Close affordances',
    body: 'Always offer a visible close button in the corner. Don’t rely only on Esc or the backdrop for pointer outside presses. Touch screen readers and accessibility users benefit from a clear, targetable control to click to close the dialog.',
  },
  {
    title: 'Forms inside dialogs',
    body: 'Keep forms short; longer flows usually deserve a full page. Validate inline, keep button text specific (“Create project”), and disable destructive actions until the input is valid.',
  },
  {
    title: 'Content guidelines',
    body: 'Lead with the outcome (“Rename project?”) and follow with one or two short, concrete sentences. Avoid long prose; link out for details instead.',
  },
  {
    title: 'SSR and hydration notes',
    body: 'Because dialogs render in a portal, make sure your portal container exists on the client.',
  },
  {
    title: 'Mobile ergonomics',
    body: 'Use larger touch targets and keep the close button reachable with the thumb. Avoid full-screen modals unless the task truly needs a whole screen.',
  },
  {
    title: 'Theming and density',
    body: 'Match spacing and corner radius to your system. Use a slightly denser layout than pages so the dialog feels purpose-built, not like a mini web page.',
  },
  {
    title: 'Internationalization',
    body: 'Plan for longer text. Buttons can grow to two lines; titles should wrap gracefully. Keep destructive terms consistent across locales.',
  },
  {
    title: 'Performance',
    body: 'Children are mounted lazily when the dialog opens. If the dialog can reopen often, consider the `keepMounted` prop sparingly to perform the work only once on mount to avoid re-initializing complex component trees on each open.',
  },
  {
    title: 'When a popover is better',
    body: 'If the content is a small hint or a few quick actions anchored to a control, use a popover or menu instead of a dialog. Dialogs interrupt on purpose—use that sparingly.',
  },
  {
    title: 'Follow-up and cleanup',
    body: 'After a successful action, close the dialog and show confirmation in context (toast, inline message, or updated UI) so people can see the result of what they just did.',
  },
];
</script>

<template>
  <Dialog.Root>
    <Dialog.Trigger :class="styles.Button">Open dialog</Dialog.Trigger>
    <Dialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <Dialog.Backdrop :class="styles.Backdrop" />
      </Transition>
      <Dialog.Viewport :class="styles.Viewport">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Dialog.Popup :class="styles.Popup">
            <div :class="styles.Header">
              <Dialog.Title :class="styles.Title">Dialog</Dialog.Title>
              <Dialog.Description :class="styles.Description">
                This layout keeps the popup fully on screen while allowing its content to scroll.
              </Dialog.Description>
            </div>
            <div :class="styles.Body" tabindex="0">
              <section v-for="item in CONTENT_SECTIONS" :key="item.title" :class="styles.Section">
                <h3 :class="styles.SectionTitle">{{ item.title }}</h3>
                <p :class="styles.SectionBody">{{ item.body }}</p>
              </section>
            </div>
            <div :class="styles.Actions">
              <Dialog.Close :class="styles.Button">Close</Dialog.Close>
            </div>
          </Dialog.Popup>
        </Transition>
      </Dialog.Viewport>
    </Dialog.Portal>
  </Dialog.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);
    }
  }

  &: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);
    }
  }

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

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

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

  @supports (-webkit-touch-callout: none) {
    position: absolute;
  }

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

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

.Viewport {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 0;
  overflow: hidden;

  @media (min-height: 600px) {
    padding: 2rem 0 3rem;
  }
}

.Popup {
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(40rem, calc(100% - 2rem));
  max-height: 100%;
  max-width: 100%;
  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;
  min-height: 0;

  @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: scale(0.98);
}

.Header {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem;
  border-bottom: 1px solid oklch(14.5% 0 0deg);

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

.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);
  }
}

.Body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;

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

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

.Section {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem;
}

.SectionTitle {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 700;
}

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

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

.Actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem;
  border-top: 1px solid oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    border-color: white;
  }
}
vue
<script setup lang="ts">
import { Dialog } from '@vase-ui/vue/dialog';

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

const CONTENT_SECTIONS = [
  {
    title: 'What a dialog is for',
    body: 'Use a dialog when you need the user to complete a focused task or read something important without navigating away. It opens on top of the page and returns focus back where it started when closed.',
  },
  {
    title: 'Anatomy at a glance',
    body: 'Root, Trigger, Portal, Backdrop, Popup, Title/Description, Close. Keep the title short and the first paragraph specific so screen readers announce something meaningful.',
  },
  {
    title: 'Opening and closing',
    body: 'Control it using external state via `v-model:open`, or let it manage state for you internally.',
  },
  {
    title: 'Keyboard and focus behavior',
    body: 'Focus moves inside the dialog when it opens. Tab and Shift+Tab loop within, and Esc requests close.',
  },
  {
    title: 'Accessible labeling',
    body: 'Set an explicit title and description using the `Dialog.Title` and `Dialog.Description` components.',
  },
  {
    title: 'Backdrop and page scrolling',
    body: 'The backdrop visually separates layers while background content is inert. Don’t rely on dimness alone—keep copy clear and buttons obvious so actions are easy to choose.',
  },
  {
    title: 'Portals and stacking',
    body: 'Dialogs render in a portal so they sit above the `isolation: isolate` app content and avoid local z-index wars.',
  },
  {
    title: 'Viewport overflow',
    body: 'Let long content overflow the bottom edge and reveal as you scroll the page container. Keep generous padding at the top and bottom so the dialog doesn’t feel jammed against the edges.',
  },
  {
    title: 'Nested dialogs and confirmations',
    body: 'If closing a dialog needs confirmation, open a child alert dialog rather than mutating the current one. The parent stays visible behind it; only the topmost layer should feel interactive.',
  },
  {
    title: 'Transitions that respect motion settings',
    body: 'Use small, fast transitions (opacity plus a few pixels of Y translation or scale). Subtle motion helps people notice what changed without slowing them down.',
  },
  {
    title: 'Controlled vs. uncontrolled',
    body: 'Controlled state is best when other parts of the page need to react to open/close. Uncontrolled is fine for local cases where only the dialog matters.',
  },
  {
    title: 'Close affordances',
    body: 'Always offer a visible close button in the corner. Don’t rely only on Esc or the backdrop for pointer outside presses. Touch screen readers and accessibility users benefit from a clear, targetable control to click to close the dialog.',
  },
  {
    title: 'Forms inside dialogs',
    body: 'Keep forms short; longer flows usually deserve a full page. Validate inline, keep button text specific (“Create project”), and disable destructive actions until the input is valid.',
  },
  {
    title: 'Content guidelines',
    body: 'Lead with the outcome (“Rename project?”) and follow with one or two short, concrete sentences. Avoid long prose; link out for details instead.',
  },
  {
    title: 'SSR and hydration notes',
    body: 'Because dialogs render in a portal, make sure your portal container exists on the client.',
  },
  {
    title: 'Mobile ergonomics',
    body: 'Use larger touch targets and keep the close button reachable with the thumb. Avoid full-screen modals unless the task truly needs a whole screen.',
  },
  {
    title: 'Theming and density',
    body: 'Match spacing and corner radius to your system. Use a slightly denser layout than pages so the dialog feels purpose-built, not like a mini web page.',
  },
  {
    title: 'Internationalization',
    body: 'Plan for longer text. Buttons can grow to two lines; titles should wrap gracefully. Keep destructive terms consistent across locales.',
  },
  {
    title: 'Performance',
    body: 'Children are mounted lazily when the dialog opens. If the dialog can reopen often, consider the `keepMounted` prop sparingly to perform the work only once on mount to avoid re-initializing complex component trees on each open.',
  },
  {
    title: 'When a popover is better',
    body: 'If the content is a small hint or a few quick actions anchored to a control, use a popover or menu instead of a dialog. Dialogs interrupt on purpose—use that sparingly.',
  },
  {
    title: 'Follow-up and cleanup',
    body: 'After a successful action, close the dialog and show confirmation in context (toast, inline message, or updated UI) so people can see the result of what they just did.',
  },
];
</script>

<template>
  <Dialog.Root>
    <Dialog.Trigger
      class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
      >Open dialog</Dialog.Trigger
    >
    <Dialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <Dialog.Backdrop
          class="fixed inset-0 bg-black/20 dark:bg-black/50 transition-opacity duration-150 supports-[-webkit-touch-callout:none]:absolute"
        />
      </Transition>
      <Dialog.Viewport
        class="fixed inset-0 flex items-center justify-center overflow-hidden py-6 [@media(min-height:600px)]:pb-12 [@media(min-height:600px)]:pt-8"
      >
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Dialog.Popup
            class="relative flex w-[min(40rem,calc(100%-2rem))] max-h-full max-w-full min-h-0 flex-col bg-white dark:bg-neutral-950 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 p-4 border-b border-neutral-950 dark:border-white">
              <Dialog.Title class="text-base font-bold">Dialog</Dialog.Title>
              <Dialog.Description class="text-sm text-neutral-600 dark:text-neutral-400">
                This layout keeps the popup fully on screen while allowing its content to scroll.
              </Dialog.Description>
            </div>
            <div
              class="flex-auto overflow-y-auto overscroll-contain focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
              tabindex="0"
            >
              <section
                v-for="item in CONTENT_SECTIONS"
                :key="item.title"
                class="flex flex-col gap-1 p-4"
              >
                <h3 class="text-sm font-bold">{{ item.title }}</h3>
                <p class="text-sm text-neutral-700 dark:text-neutral-300">{{ item.body }}</p>
              </section>
            </div>
            <div class="flex justify-end gap-3 p-4 border-t border-neutral-950 dark:border-white">
              <Dialog.Close
                class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
                >Close</Dialog.Close
              >
            </div>
          </Dialog.Popup>
        </Transition>
      </Dialog.Viewport>
    </Dialog.Portal>
  </Dialog.Root>
</template>

Placing elements outside the popup ​

To show an element "outside" the colored area of the popup, keep it in Dialog.Popup, and give the popup styles to a child element. The element then stays in the tab order, and screen readers announce it correctly.

Dialog.Popup has pointer-events: none. The inner content (the colored popup and the close button) has pointer-events: auto, so a click on the backdrop still closes the dialog.

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

const backdropHiddenClass = styles.BackdropHidden;
const popupHiddenClass = styles.PopupRootHidden;
const panelEnterFromClass = styles.PopupEnterFrom;

const XIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      style: { display: 'block' },
    },
    [h('path', { d: 'm2.5 2.5 11 11m-11 0 11-11' })],
  );
</script>

<template>
  <Dialog.Root>
    <Dialog.Trigger :class="styles.Button">Open dialog</Dialog.Trigger>
    <Dialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <Dialog.Backdrop :class="styles.Backdrop" />
      </Transition>
      <Dialog.Viewport :class="styles.Viewport">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Dialog.Popup :class="styles.PopupRoot" aria-label="Uncontained dialog">
            <Dialog.Close :class="styles.Close" aria-label="Close">
              <XIcon />
            </Dialog.Close>
            <Transition :enter-from-class="panelEnterFromClass" appear>
              <div :class="styles.Popup" />
            </Transition>
          </Dialog.Popup>
        </Transition>
      </Dialog.Viewport>
    </Dialog.Portal>
  </Dialog.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);
    }
  }

  &: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);
    }
  }

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

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

.Backdrop {
  position: fixed;
  inset: 0;
  background-color: rgb(0 0 0 / 20%);
  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) {
    background-color: rgb(0 0 0 / 50%);
  }
}

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

.Viewport {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 3rem 1rem;

  @media (min-width: 80rem) {
    padding-block: 1.5rem;
  }
}

.PopupRoot {
  position: relative;
  display: flex;
  justify-content: center;
  width: 100%;
  max-width: 70rem;
  height: 100%;
  transition: opacity 150ms;
  pointer-events: none;

  @media (min-width: 80rem) {
    max-width: none;
  }
}

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

.Popup {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  max-width: 70rem;
  padding: 1rem;
  pointer-events: auto;
  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 500ms cubic-bezier(0.22, 1, 0.36, 1);

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

/* The enter-from class of the `<Transition>` around the panel. */
.PopupEnterFrom {
  transform: scale(1.05);
}

.Close {
  box-sizing: border-box;
  position: absolute;
  top: -2.5rem;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  width: 2rem;
  height: 2rem;
  margin: 0;
  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%);

  @media (min-width: 80rem) {
    top: 0;
  }

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

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

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

  &:active {
    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;
    }
  }
}
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Dialog } from '@vase-ui/vue/dialog';

const backdropHiddenClass = 'opacity-0';
const popupHiddenClass = 'opacity-0';
const panelEnterFromClass = 'scale-105';

const XIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      style: { display: 'block' },
    },
    [h('path', { d: 'm2.5 2.5 11 11m-11 0 11-11' })],
  );
</script>

<template>
  <Dialog.Root>
    <Dialog.Trigger
      class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
      >Open dialog</Dialog.Trigger
    >
    <Dialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <Dialog.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>
      <Dialog.Viewport class="fixed inset-0 grid place-items-center px-4 py-12 xl:py-6">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Dialog.Popup
            aria-label="Uncontained dialog"
            class="relative flex h-full w-full max-w-[70rem] xl:max-w-none justify-center pointer-events-none transition-opacity duration-150"
          >
            <Dialog.Close
              class="absolute right-0 -top-10 flex h-8 w-8 items-center justify-center border border-neutral-950 dark:border-white bg-white dark:bg-neutral-950 text-neutral-950 dark:text-white shadow-[0.25rem_0.25rem_0] shadow-black/12 dark:shadow-none hover:bg-neutral-100 dark:hover:bg-neutral-800 active:bg-neutral-200 dark:active:bg-neutral-700 xl:top-0 pointer-events-auto focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
              aria-label="Close"
            >
              <XIcon />
            </Dialog.Close>
            <Transition :enter-from-class="panelEnterFromClass" appear>
              <div
                class="pointer-events-auto h-full w-full max-w-[70rem] 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] duration-500 ease-[cubic-bezier(0.22,1,0.36,1)]"
              />
            </Transition>
          </Dialog.Popup>
        </Transition>
      </Dialog.Viewport>
    </Dialog.Portal>
  </Dialog.Root>
</template>

Detached triggers ​

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

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

The methods of the handle, such as open() and openWithPayload(), act only while a Dialog.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 { Dialog } from '@vase-ui/vue/dialog';

const demoDialog = Dialog.createHandle();
</script>

<template>
  <Dialog.Trigger :handle="demoDialog">Open</Dialog.Trigger>

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

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

const demoDialog = Dialog.createHandle();
</script>

<template>
  <Dialog.Trigger :class="styles.Button" :handle="demoDialog">View notifications</Dialog.Trigger>

  <Dialog.Root :handle="demoDialog">
    <Dialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <Dialog.Backdrop :class="styles.Backdrop" />
      </Transition>
      <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
        <Dialog.Popup :class="styles.Popup">
          <div :class="styles.Intro">
            <Dialog.Title :class="styles.Title">Notifications</Dialog.Title>
            <Dialog.Description :class="styles.Description">
              You are all caught up. Good job!
            </Dialog.Description>
          </div>
          <div :class="styles.Actions">
            <Dialog.Close :class="styles.Button">Close</Dialog.Close>
          </div>
        </Dialog.Popup>
      </Transition>
    </Dialog.Portal>
  </Dialog.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);
    }
  }

  &: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);
    }
  }

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

    @media (prefers-color-scheme: dark) {
      outline-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;
}

.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 { Dialog } from '@vase-ui/vue/dialog';

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

const demoDialog = Dialog.createHandle();
</script>

<template>
  <Dialog.Trigger
    class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
    :handle="demoDialog"
    >View notifications</Dialog.Trigger
  >

  <Dialog.Root :handle="demoDialog">
    <Dialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <Dialog.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">
        <Dialog.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">
            <Dialog.Title class="text-base font-bold">Notifications</Dialog.Title>
            <Dialog.Description class="text-sm text-neutral-600 dark:text-neutral-400">
              You are all caught up. Good job!
            </Dialog.Description>
          </div>
          <div class="flex justify-end gap-3">
            <Dialog.Close
              class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
              >Close</Dialog.Close
            >
          </div>
        </Dialog.Popup>
      </Transition>
    </Dialog.Portal>
  </Dialog.Root>
</template>

Multiple triggers ​

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

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

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

const demoDialog = Dialog.createHandle();
</script>

<template>
  <Dialog.Trigger :handle="demoDialog">Trigger 1</Dialog.Trigger>
  <Dialog.Trigger :handle="demoDialog">Trigger 2</Dialog.Trigger>

  <Dialog.Root :handle="demoDialog">
    <Dialog.Portal>
      <Dialog.Popup>Dialog</Dialog.Popup>
    </Dialog.Portal>
  </Dialog.Root>
</template>

The dialog can show different content for each trigger. Give a payload to each Dialog.Trigger. The default slot of Dialog.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 { Dialog } from '@vase-ui/vue/dialog';

const demoDialog = Dialog.createHandle<{ text: string }>();
</script>

<template>
  <Dialog.Trigger :handle="demoDialog" :payload="{ text: 'Trigger 1' }">Trigger 1</Dialog.Trigger>
  <Dialog.Trigger :handle="demoDialog" :payload="{ text: 'Trigger 2' }">Trigger 2</Dialog.Trigger>

  <Dialog.Root :handle="demoDialog">
    <template #default="{ payload }">
      <Dialog.Portal>
        <Dialog.Popup>
          <Dialog.Title>Dialog</Dialog.Title>
          <Dialog.Description v-if="payload !== undefined">
            This has been opened by {{ payload.text }}
          </Dialog.Description>
        </Dialog.Popup>
      </Dialog.Portal>
    </template>
  </Dialog.Root>
</template>

Controlled mode with multiple triggers ​

To control the open state, bind it with v-model:open on Dialog.Root. With more than one trigger, also bind the active trigger with v-model:trigger-id, and give an id to each Dialog.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 { Dialog } from '@vase-ui/vue/dialog';
import styles from '../../_index.module.css';

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

const demoDialog = Dialog.createHandle<number>();

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

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

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

<template>
  <div :class="styles.Container">
    <Dialog.Trigger id="trigger-1" :class="styles.Button" :handle="demoDialog" :payload="1">
      Open 1
    </Dialog.Trigger>

    <Dialog.Trigger id="trigger-2" :class="styles.Button" :handle="demoDialog" :payload="2">
      Open 2
    </Dialog.Trigger>

    <Dialog.Trigger id="trigger-3" :class="styles.Button" :handle="demoDialog" :payload="3">
      Open 3
    </Dialog.Trigger>

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

  <Dialog.Root
    :handle="demoDialog"
    :open="open"
    :trigger-id="triggerId"
    @open-change="handleOpenChange"
  >
    <template #default="{ payload }">
      <Dialog.Portal>
        <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
          <Dialog.Backdrop :class="styles.Backdrop" />
        </Transition>
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Dialog.Popup :class="styles.Popup">
            <Dialog.Title v-if="payload !== undefined" :class="styles.Title">
              Dialog {{ payload }}
            </Dialog.Title>
            <div :class="styles.Actions">
              <Dialog.Close :class="styles.Button">Close</Dialog.Close>
            </div>
          </Dialog.Popup>
        </Transition>
      </Dialog.Portal>
    </template>
  </Dialog.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);
    }
  }

  &: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);
    }
  }

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

    @media (prefers-color-scheme: dark) {
      outline-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;
}

.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 { Dialog } from '@vase-ui/vue/dialog';

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

const demoDialog = Dialog.createHandle<number>();

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

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

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

<template>
  <div class="flex flex-wrap gap-2 justify-center">
    <Dialog.Trigger
      id="trigger-1"
      class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
      :handle="demoDialog"
      :payload="1"
    >
      Open 1
    </Dialog.Trigger>

    <Dialog.Trigger
      id="trigger-2"
      class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
      :handle="demoDialog"
      :payload="2"
    >
      Open 2
    </Dialog.Trigger>

    <Dialog.Trigger
      id="trigger-3"
      class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
      :handle="demoDialog"
      :payload="3"
    >
      Open 3
    </Dialog.Trigger>

    <button
      class="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:bg-neutral-100 dark:hover:bg-neutral-800 active:bg-neutral-200 dark:active:bg-neutral-700 disabled:border-neutral-500 disabled:text-neutral-500 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
      type="button"
      @click="openProgrammatically"
    >
      Open programmatically
    </button>
  </div>

  <Dialog.Root
    :handle="demoDialog"
    :open="open"
    :trigger-id="triggerId"
    @open-change="handleOpenChange"
  >
    <template #default="{ payload }">
      <Dialog.Portal>
        <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
          <Dialog.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">
          <Dialog.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"
          >
            <Dialog.Title v-if="payload !== undefined" class="text-base font-bold">
              Dialog {{ payload }}
            </Dialog.Title>
            <div class="flex justify-end gap-3">
              <Dialog.Close
                class="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 disabled:border-neutral-500 disabled:text-neutral-500 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
                >Close</Dialog.Close
              >
            </div>
          </Dialog.Popup>
        </Transition>
      </Dialog.Portal>
    </template>
  </Dialog.Root>
</template>

Open from a menu ​

To open a dialog from a menu, bind the open state of the 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 { Dialog } from '@vase-ui/vue/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">Details…</Menu.Item>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>

  <Dialog.Root v-model:open="dialogOpen">
    <Dialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <Dialog.Backdrop :class="styles.Backdrop" />
      </Transition>
      <Transition
        :enter-from-class="dialogPopupHiddenClass"
        :leave-to-class="dialogPopupHiddenClass"
      >
        <Dialog.Popup :class="styles.DialogPopup">
          <div :class="styles.Intro">
            <Dialog.Title :class="styles.Title">Playlist details</Dialog.Title>
            <Dialog.Description :class="styles.Description">
              This playlist contains 24 songs and was last updated today.
            </Dialog.Description>
          </div>
          <div :class="styles.Actions">
            <Dialog.Close :class="styles.Button">Close</Dialog.Close>
          </div>
        </Dialog.Popup>
      </Transition>
    </Dialog.Portal>
  </Dialog.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;
  }

  @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 { Dialog } from '@vase-ui/vue/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">Details…</Menu.Item>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>

  <Dialog.Root v-model:open="dialogOpen">
    <Dialog.Portal>
      <Transition :enter-from-class="backdropHiddenClass" :leave-to-class="backdropHiddenClass">
        <Dialog.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"
      >
        <Dialog.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">
            <Dialog.Title class="text-base font-bold">Playlist details</Dialog.Title>
            <Dialog.Description class="text-sm text-neutral-600 dark:text-neutral-400">
              This playlist contains 24 songs and was last updated today.
            </Dialog.Description>
          </div>
          <div class="flex justify-end gap-3">
            <Dialog.Close :class="buttonClass">Close</Dialog.Close>
          </div>
        </Dialog.Popup>
      </Transition>
    </Dialog.Portal>
  </Dialog.Root>
</template>

Render on the server ​

Set disabled on Dialog.Portal to render the parts in place. The server HTML then has the open popup.

This panel stays beside a list on wide screens and becomes a modal sheet on narrow screens. It keeps one dialog tree and changes modal after the hydration:

vue
<script setup lang="ts">
import { onMounted, onUnmounted, ref, useId } from 'vue';
import { Dialog } from '@vase-ui/vue/dialog';

const open = ref(true);
const isNarrow = ref(false);
let narrowQuery: MediaQueryList | undefined;
function updateNarrow({ matches }: { matches: boolean }) {
  isNarrow.value = matches;
}
onMounted(() => {
  narrowQuery = window.matchMedia('(max-width: 48rem)');
  updateNarrow(narrowQuery);
  narrowQuery.addEventListener('change', updateNarrow);
});
onUnmounted(() => narrowQuery?.removeEventListener('change', updateNarrow));
const titleId = useId();
</script>

<template>
  <div class="layout">
    <ul>
      <li><button type="button" @click="open = true">Task details</button></li>
    </ul>
    <Dialog.Root
      :open="open"
      :modal="isNarrow"
      :disable-pointer-dismissal="!isNarrow"
      @open-change="open = $event"
    >
      <Dialog.Portal disabled>
        <div :data-modal="isNarrow || undefined" class="portal">
          <Dialog.Backdrop class="backdrop" />
          <Dialog.Popup
            :aria-labelledby="titleId"
            :initial-focus="isNarrow ? undefined : false"
            class="panel"
          >
            <Dialog.Title :id="titleId">Task details</Dialog.Title>
            <p>Review the draft before Friday.</p>
            <Dialog.Close>Close</Dialog.Close>
          </Dialog.Popup>
        </div>
      </Dialog.Portal>
    </Dialog.Root>
  </div>
</template>

<style scoped>
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
}

.backdrop {
  display: none;
}

.panel {
  position: relative;
  padding: 1rem;
  border: 1px solid;
  background: canvas;
  color: canvastext;
}

.portal[data-modal] .backdrop {
  display: block;
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 25%);
}

.portal[data-modal] .panel {
  position: fixed;
  inset: auto 0 0;
  max-height: 80dvh;
  overflow: auto;
}
</style>

Give a modal popup a position, so that it is above the fixed element of the dialog. Hide Dialog.Backdrop with CSS while the dialog is not modal. The server HTML has no fixed element, and the modal state starts at the mount.

The popup gets aria-labelledby and aria-describedby after the hydration. For a name in the server HTML, give Dialog.Title an id, and give the same id to the popup as aria-labelledby. Do the same with Dialog.Description and aria-describedby.

API reference ​

Dialog.Root ​

Groups the parts of the dialog. 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.
disablePointerDismissalboolean | undefinedfalseA press outside does not close the dialog. A dialog that is not modal also stays open when the focus leaves it.
handleDialogHandle<Payload> | undefinedConnects the root to triggers outside it and to code.
modalboolean | "trap-focus" | undefinedtrueThe modal state of the open dialog: - true: the focus stays in the popup, and the rest of the page is inert. The page does not scroll, and a fixed element covers it. - 'trap-focus': the focus stays in the popup, and screen readers do not read the rest of the page. The page stays in use for the pointer. - false: the page stays in use. The dialog closes when the focus leaves it, unless disablePointerDismissal is set. Put a Close part in the popup: a touch screen reader needs it to leave a dialog that keeps the focus.
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 dialog. payload is the payload of the active trigger.

Events

EventArgumentsDescription
openChange[open: boolean, details: DialogRootChangeEventDetails]The 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 dialog with the reason 'imperative-action'.

Dialog.Trigger ​

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

Props

PropTypeDefaultDescription
disabledboolean | undefinedfalseThe user cannot press the trigger.
handleDialogHandle<Payload> | undefinedConnects the trigger to a root outside it.
idstring | undefinedThe root names the active trigger by this id in triggerId.
payloadPayload | undefinedThe payload that the 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: DialogTriggerState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: DialogTriggerState
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 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.

Dialog.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.

Dialog.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 dialog is closed, and keepMounted of the portal keeps the backdrop in the DOM.

Dialog.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 dialog is closed, and keepMounted of the portal keeps the viewport in the DOM.
[data-nested]The root of the 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 dialog.
:has(> .v-leave-active)The popup leaves. Use the leave class of the <Transition> around the popup.

Dialog.Popup ​

The container of the content of the dialog. 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 dialog is closed, and keepMounted of the portal keeps the popup in the DOM.
[data-nested]The root of the 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 dialog.

CSS variables

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

Dialog.Title ​

A heading that names the 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.

Dialog.Description ​

A paragraph that describes the 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.

Dialog.Close ​

A button that closes the 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 a Dialog.Root to Dialog.Trigger parts outside it.

Return value

DialogHandle<Payload>

Handle ​

The class of the handle, which opens and closes the 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 Dialog from Base UI 1.9.0.

API ​

Base UIVase UI
Dialog.Root prop onOpenChangeCompleteListen to @after-enter and @after-leave of the <Transition> around the popup. They run after its animations end.
Dialog.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.
Dialog.Trigger prop nativeButtonThe trigger reads its element to know if it is a native button, so it needs no nativeButton.
Dialog.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.
Dialog.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.
Dialog.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.
Dialog.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.
Dialog.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
Dialog.Portaldisabled propThe portal is a <Teleport>. With disabled, it renders its content in place, also in the server HTML.
Dialog.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.
Dialog.Rootupdate:triggerId eventv-model:trigger-id binds the active trigger, as v-model:open binds the open state.

Return types ​

FunctionVase UI returnsWhy
Dialog.createHandleDialogHandle<Payload>The return type names the class DialogHandle, which the namespace exports as Dialog.Handle.

Behavior ​

Vase UIEvidence
With two mounted titles in one dialog or one popover, the popup names the title that mounted last in aria-labelledby. When that title unmounts, the popup names the title that stays. Base UI then gives the popup no aria-labelledby, because the title that stays does not write its id again. Two descriptions follow the same rule for aria-describedby.
Each Portal part takes disabled, as <Teleport> does. A disabled portal renders its content in place, also in the server HTML, and it ignores to. A dialog in place that is not modal has the tab order of the document. A modal dialog in place keeps the focus in its popup. Base UI renders its portal only after the mount.
A touch outside an open popup closes it only at a tap. A tap ends with pointerup in less than 1 s and moves 8 px or less. Chromium on Android sends click for a move of 8 px and not for 8.1 px, the smallest limit of the measured browsers. A touch that scrolls the page ends with pointercancel and closes nothing, as a native popover stays open in Chromium and WebKit. A drag of more than 8 px on an element that does not scroll also closes nothing. A tap on a backdrop, or on the element that a modal popup puts over the page, closes the popup and gives the page under it no click. In Base UI, a touch that scrolls the page closes a Popover, a Menu or a Select.
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.