vael-ui v0.5.7

Overlays

Layout

Drawer

A panel that slides in from an edge of the screen. Use it for navigation, filters or details beside the page.

Install

import { Drawer } from 'vael-ui'

Playground

Placement, behaviour and animation

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

const open = ref(false)
</script>

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

Props

NameTypeDefaultDescription
side'top' | 'right' | 'bottom' | 'left''right'Which viewport edge the panel slides in from.
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.
motionDialogMotionHow 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.
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.
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.
openbooleanfalseWhether the drawer is open.
maximizedbooleanfalseWhether the panel fills the viewport. Dialog's built-in toggle manages it unless you bind it.

Events

NameTypeDescription
open-change(value: boolean, details: DialogOpenChangeDetails)Fires before the drawer closes, with the reason. Call details.cancel() to keep it open.
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; }Panel content.
header{ close: () => void; }Replaces the default title and description header.

Exposed

NameTypeDescription
panelElHTMLElement | nullPanel element (null while closed).
overlayElHTMLElement | nullBackdrop element. null while closed or when modal is false.
isClosingbooleantrue while a beforeClose close is pending.
close() => voidCloses the drawer, running beforeClose first.
cancelClose() => voidCancels a close pending in beforeClose and keeps the drawer open.

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.

<Drawer
  :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 drawer, unless closeOnEsc is false.
TabMoves focus to the next element in the drawer, wrapping from the last to the first.
ShiftTabMoves focus to the previous element in the drawer, wrapping from the first to the last.
  • Drawer is a Dialog anchored to an edge, so it has the same roles, labels, focus behavior and inert page.
  • title wires aria-labelledby and description wires aria-describedby. Without title, pass aria-label.
  • Focus moves into the drawer on open and returns to the element that opened it on close.