Veil UI
Components

Modal

A centered dialog with overlay, header, footer and a close button.

Installation

$ npx veil-ui@latest add modal

Usage

import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/modal";

<Dialog>
  <DialogTrigger asChild>
    <button type="button">Open modal</button>
  </DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Edit profile</DialogTitle>
      <DialogDescription>Update your details and save.</DialogDescription>
    </DialogHeader>
    {/* form fields */}
    <DialogFooter>{/* actions */}</DialogFooter>
  </DialogContent>
</Dialog>;

Examples

Basic

Form

No close button

API reference

  • Dialog is the root and DialogTrigger opens it; both accept controlled open / onOpenChange.
  • DialogContent renders a portal, overlay and close button (showCloseButton opts out).
  • DialogHeader, DialogTitle, DialogDescription and DialogFooter compose the layout.

Accessibility

  • Uses role="dialog" with a required title and optional description for the accessible name.
  • Focus is trapped inside, Escape and the overlay close it, and focus returns to the trigger.
  • The default close button is labelled Close dialog.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add modal --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { DialogClose, DialogContent, DialogPortal } from "reka-ui";
import { X } from "lucide-vue-next";

import { cn } from "@/lib/utils";

import DialogOverlay from "./DialogOverlay.vue";

const props = withDefaults(
  defineProps<{ class?: string; showCloseButton?: boolean }>(),
  { showCloseButton: true },
);
</script>

<template>
  <DialogPortal>
    <DialogOverlay />
    <DialogContent
      data-slot="modal-content"
      :class="
        cn(
          'fixed top-1/2 left-1/2 z-50 grid w-[calc(100%-2rem)] max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 rounded-lg border bg-background p-6 shadow-lg outline-none',
          'data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
          'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95',
          props.class,
        )
      "
    >
      <slot />
      <DialogClose
        v-if="showCloseButton"
        data-slot="modal-close"
        aria-label="Close dialog"
        class="absolute top-3 right-3 rounded-sm p-1 text-muted-foreground opacity-70 outline-none transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring"
      >
        <X class="size-4" aria-hidden="true" />
      </DialogClose>
    </DialogContent>
  </DialogPortal>
</template>

On this page