vael-ui v0.5.7

Overlays

Layout

Dialog

A modal window over the page that waits until someone responds or dismisses it. Use it for a task or a decision that needs an answer first.

Install

import { Dialog } from 'vael-ui'

Playground

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { ref } from 'vue'
import { Dialog } from 'vael-ui'

const open = ref(false)
</script>

<template>
  <Dialog v-model:open="open">
    <p>This is the dialog body. Put any content here.</p>
  </Dialog>
</template>

Props

NameTypeDefaultDescription
size'sm' | 'md' | 'lg''md'Panel width: 'sm' is 22rem, 'md' is 28rem, 'lg' is 38rem.
uiPartial<Record<'overlay' | 'panel' | 'header' | 'title' | 'description' | 'body' | 'footer' | 'maximize' | 'close', UiPartValue>>Class and style overrides for each part.
closeOnEscbooleantrueEscape key closes the panel.
beforeCloseBeforeClose<DialogCloseReason>Runs before the dialog closes. Return true to close it, false to keep it open, or a promise of either, like () => confirmAction(…).result. The dialog stays open while the promise is pending.
forceMountbooleanfalseKeeps it mounted while closed, toggled with v-show, so its content keeps its state. vael-ui then leaves its motion to you.
teleportTostringTeleport target: a CSS selector. Wins over container either way.
scrollFadebooleantrueMasks the panel's top/bottom edge as its content scrolls under it, signaling there's more.
position'top' | 'right' | 'bottom' | 'left' | 'center''center'Where the panel anchors in the viewport.
containerDOMTargetScopes the panel to an element instead of the viewport. The overlay, scroll lock and modality apply only inside it. It's also the teleport target unless you set teleportTo.
titlestringRenders the default header and wires aria-labelledby automatically.
descriptionstringMuted line under the title; wires aria-describedby automatically.
role'dialog' | 'alertdialog''dialog'Use 'alertdialog' for urgent messages that need a response, such as confirmations. Screen readers announce it more assertively.
origin'trigger' | 'center''center''trigger' zooms the panel out of the element that opened it, and back into it on close, for a dialog that expands from a card or a button. Centred dialogs only.
initialFocus(() => HTMLElement | null | undefined)Returns the element to focus on open. Return null or undefined to focus an [autofocus] element, else the first control in the body or footer.
showClosebooleantrueShows the built-in close button (×). Hide it when the footer carries the only sensible actions.
modalbooleantruefalse turns off the overlay, scroll lock, focus trap and the inert page behind it, and a dialog you press or focus comes to the front of the other open ones. Escape-close, layer stacking, focus on open and focus return still apply.
flushbooleanfalsetrue removes edge padding: a top/bottom Dialog sits flush to the viewport edge instead of floating (a Drawer's always does).
closeOnOverlaybooleantrueClicking the overlay closes the panel. Has no effect when modal is false (no overlay to click).
closeOnHistoryBackbooleanfalseThe browser or mobile back action closes the panel instead of leaving the page. Opening pushes a history entry, and any other close removes it.
scrollTargetDOMTargetElement to scroll-lock while open. Defaults to container; pass the inner scroller when the container itself doesn't scroll.
maximizablebooleanfalseAdds a maximize/restore toggle to the header, filling the viewport when active.
motionDialogMotion<N>How it moves: false for instantly, { spring } to retime the built-in motion, states by part (initial: { panel: { … } }), your targets, or enter/leave hooks for a library. Unset, it follows the nearest ConfigProvider's style.
openbooleanfalseWhether the dialog is open.
maximizedbooleanfalseWhether the panel fills the viewport. The built-in toggle manages it unless you bind v-model:maximized.

Events

NameTypeDescription
open-change(value: boolean, details: DialogOpenChangeDetails)Fires when a close is requested; call details.cancel() to keep the dialog open.
after-enter()Fires once it has finished opening.
after-leave()Fires once it has finished closing.
update:open(value: boolean)Fires when open changes (v-model:open).
update:maximized(value: boolean)Fires when maximized changes (v-model:maximized).

Slots

NameTypeDescription
default{ close: () => void; open: boolean; isClosing: boolean; cancelClose: () => void; panelEl: HTMLElement | null; target: (name: N) => MotionRef; phase: MotionPhase; }Body content; receives close, open, isClosing, cancelClose, panelEl, target and phase.
header{ close: () => void; }Replaces the default title/description header.

Exposed

NameTypeDescription
panelElHTMLElement | nullPanel element (null while closed).
phaseMotionPhase'entering' | 'entered' | 'leaving' | 'left'.
overlayElHTMLElement | nullBackdrop element. null while closed or when modal is false. With forceMount, an inline opacity on it replaces the built-in fade.
isClosingbooleantrue while a beforeClose close is pending.
close() => voidCloses the dialog, running @open-change and beforeClose first.
cancelClose() => voidCancels a close pending in beforeClose and keeps the dialog open.
maximizedbooleanWhether the panel is maximized.

Motion New

Dialog's motion, and Drawer's and BottomSheet's: values or hooks for its parts (DialogPart), how it opens and closes (morph, linked, exitOrder, resize) and swapped content. false turns it off.

<Dialog
  :motion="{
    initial: { panel: { opacity: 0, y: 8, scale: 0.98 } },
    spring: { damping: 0.85, response: 0.35 },
  }"
/>
NameTypeDescription
initialexitoverlaypanelheadertitledescriptionbodyfootermaximizecloseSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
morphlinkedexitOrder'trigger' | Record<string, LinkedMotion> | 'reverse'morph: 'trigger' grows it out of the element that opened it. linked moves other elements with it, such as the page receding behind it. exitOrder: 'reverse' closes its children first.
swapresize'sync' | 'wait' | booleanContent that changes while it's open crossfades ('sync') or waits for the old view to leave ('wait'), and the box eases to its new size unless resize: false.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

Follows the Dialog (modal) pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
EscapeCloses the dialog, unless closeOnEsc is false.
TabMoves focus to the next element in the dialog, wrapping from the last to the first.
ShiftTabMoves focus to the previous element in the dialog, wrapping from the first to the last.
  • The panel has role="dialog", or role="alertdialog" with the role prop, and aria-modal="true" while modal. title wires aria-labelledby and description wires aria-describedby.
  • Without title, such as with a custom #header, pass aria-label or aria-labelledby: attributes go on the panel. The close and maximize buttons have built-in, translated labels.
  • On open, focus moves to initialFocus(), else an [autofocus] element, else the first control in the body or footer, else the first focusable element, else the panel. On close, focus returns to the element that opened it. modal: false turns off the focus trap and the inert page; focus still moves in, and returns on close unless you moved it elsewhere.
  • Escape closes only the topmost layer. While modal, the rest of the page, or of the container, is inert; toasts, live regions, tooltips and overlays opened from inside stay usable.