vael-ui v0.5.7

Overlays

Layout

BottomSheet

A panel that slides up from the bottom edge and snaps to the heights you set. Use it on touch screens, where people drag it up, down or away.

Install

import { BottomSheet } from 'vael-ui'

Playground

Placement, behaviour and animation

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

const open = ref(false)
</script>

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

Props

NameTypeDefaultDescription
titlestringRenders the default header with a built-in close button, and names the sheet.
snapPointsSheetSnapPoint[]Snap points, ordered smallest to largest. Unset, the sheet snaps at 60% and 92% of viewport height, or fills it when fullScreen is set.
initialSnapstringid of the snap point to open at. Unset, the sheet opens at the first (smallest).
dismissiblebooleantrueDragging past the smallest snap point closes the sheet.
width'sm' | 'md' | 'lg' | 'full''full'Panel width: 'full' spans edge to edge; 'sm', 'md' and 'lg' cap and center it.
fullScreenbooleanfalseUses a single snap point that covers the full viewport height. Shorthand for [{ id: 'full', height: 1 }] snap points.
scrollFadebooleantrueFades the content's top and bottom edges while there's more to scroll, like Dialog.
closeOnEscbooleantrueCloses the sheet when you press Escape.
closeOnOverlaybooleantrueCloses the sheet when you click the overlay.
modalbooleantruefalse disables the overlay, scroll lock and focus trap, so the page behind stays interactive.
closeOnHistoryBackbooleanfalsePushes a history entry on open, so the mobile back gesture or button closes the sheet. The page doesn't navigate away.
beforeCloseBeforeClose<SheetCloseReason>Runs before the sheet closes. Return true to close it, false to keep it open, or a promise of either. reason is 'drag' when it was dragged away, and velocity is the drag's release speed in px/s.
motionDialogMotionHow the sheet moves. false makes it instant. Set your own initial and exit per part, targets, or linked: elements outside the sheet that follow it, such as the page receding while it's open. Linked elements follow a drag too. Your parts replace the built-in rise and slide-out.
teleportTostringTeleport target: a CSS selector. Wins over container either way.
containerDOMTargetElement to contain the sheet in, instead of the viewport. Snap points use its height.
uiPartial<Record<'overlay' | 'panel' | 'handleZone' | 'handle' | 'header' | 'title' | 'close' | 'content', UiPartValue>>Class and style overrides for each part.
openbooleanfalseWhether the sheet is open.

Events

NameTypeDescription
update:open(value: boolean)Fires when open changes (v-model:open).

Slots

NameTypeDescription
default{ activeSnap: string | null; isDragging: boolean; isClosing: boolean; close: () => void; }Sheet content.
header{ close: () => void; }Replaces the default title and close-button row.

Exposed

NameTypeDescription
panelElHTMLElement | nullPanel element (null while closed).
overlayElHTMLElement | nullBackdrop element. null when modal is false.
activeSnapstring | nullid of the snap point the sheet rests at. Set it to move the sheet there.
isDraggingbooleanWhether you're dragging the sheet.
isClosingbooleanWhether a close is in progress (the exit animation or beforeClose hasn't finished).
close() => voidCloses the sheet with its slide-out animation.
cancelClose() => voidCancels a close pending in beforeClose and keeps the sheet open.
releaseVelocitynumberDrag speed at release in px/ms, positive toward closed. Read it in beforeClose to carry a flick on. 0 when something other than a drag closed the sheet.

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.

<BottomSheet
  :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 sheet, unless closeOnEsc is false.
TabMoves focus to the next element in the sheet, wrapping from the last to the first.
ShiftTabMoves focus to the previous element in the sheet, wrapping from the first to the last.
ArrowUpArrowDownMoves the sheet to the next larger or smaller snap point, from the drag handle.
  • Built on Dialog: the panel has role="dialog" and aria-modal="true", with the same focus trap, focus return and inert page.
  • title names the sheet through aria-labelledby. Without it, or with a custom #header, pass aria-label; it goes on the panel.
  • With more than one snap point, the drag handle is a button named “Resize sheet”. Opening focuses an [autofocus] element, else the content’s first control, else the header’s, never the handle. With one snap point, the handle is aria-hidden.
  • The header’s close button has a built-in, translated label.