vael-ui v0.5.7

Forms & inputs

Layout

DatePicker

A text field with a calendar popover for picking a date, a range or a time. Use it in forms where people type or pick a date.

Validating a form? vael-form wires this up with a schema

Install

import { DatePicker } from 'vael-ui'

Playground

Placement, behaviour and animation

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

const value = ref<Date | CalendarRange | null>(null)
const open = ref(false)
</script>

<template>
  <DatePicker
    placeholder="Choose an option"
    locale="en-US"
    v-model="value"
    v-model:open="open"
  />
</template>

Props

NameTypeDefaultDescription
selectionMode'single' | 'range''single''range' picks a start then an end; clicking before the start restarts the range.
view'date' | 'month' | 'year''date'What a click selects: a day, a month (its 1st) or a year (January 1st).
placeholderstringText shown in the input when nothing is selected.
disabledbooleanfalseDisables the input and keeps the panel from opening. A disabled parent Field also disables it.
invalidbooleanfalseStandalone override; ORed with the nearest Field's error state.
size'sm' | 'md' | 'lg''md'Input size.
minDateDateEarliest selectable date (inclusive); the calendar disables earlier days, months and years.
maxDateDateLatest selectable date (inclusive); the calendar disables later days, months and years.
disabledDatesCalendarDisabledDatesList of unavailable dates, or a predicate function. Matching compares calendar days and ignores time.
localestringBCP-47 locale for the input text, month and weekday names, and the week start day. Typed dates read in its order too: month/day/year in en-US, day/month/year in de.
firstDayOfWeeknumber0 (Sunday) to 6 (Saturday). Unset, it derives from locale and falls back to Monday.
monthsnumber1How many months the panel shows side by side, for picking a range at a glance.
closeOnSelectbooleantrueCloses the panel once a date (or a range's end) is picked. false keeps it open, for an apply button in #footer or trying a few dates; outside clicks and Escape still close it.
formatOptionsIntl.DateTimeFormatOptionsIntl.DateTimeFormat options for the input text. Unset, the format follows view, showTime and timeOnly.
namestringRenders a hidden <input> that mirrors the selection for form posts: YYYY-MM-DD, or YYYY-MM-DDTHH:mm with showTime, HH:mm with timeOnly, YYYY-MM or YYYY for a month or year view.
side'top' | 'right' | 'bottom' | 'left''bottom'Which side of the trigger the panel opens on.
align'start' | 'end' | 'center''start'How the panel aligns against the trigger along that side.
sideOffsetnumber8Gap between the trigger and the panel, in pixels.
alignOffsetnumber0Shifts the panel along the alignment axis, in pixels.
panelWidthPanelWidthThe panel's width. Unset, it is the calendar's own; 'trigger' makes it at least the field's width, and a width in px or any CSS length ('20rem') sets it. The calendar fills it and its days grow.
closeOnEscbooleantrueEscape key closes the panel.
closeOnOutsidebooleantrueClicking outside the panel closes it.
beforeCloseBeforeClose<PopoverCloseReason>Runs before the panel closes. Return true to close it, false to keep it open, or a promise of either, like () => confirmAction(…).result. The panel 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.
teleportTostring | HTMLElement'body'Teleport target: a CSS selector or element.
motionDatePickerMotiontrueHow the panel moves, like Popover's: false opens and closes it at once, and skips Calendar's month slide. An object retimes it ({ spring }), or gives values for the panel part or enter / leave hooks for your own library.
showButtonBarbooleanfalseShows built-in Today (single mode only) and Clear buttons below the calendar. Has no effect once you provide the #footer slot, which renders instead.
showYearButtonsbooleanfalseAdds « and » beside the month arrows to jump a year at a time. See Calendar's showYearButtons.
showWeekNumbersbooleanfalseShows each week's number (ISO 8601) at the start of its row.
showTimebooleanfalseAdds an hour/minute row below the calendar (single mode only). Picking a date then keeps the panel open so you can set the time.
timeOnlybooleanfalseHides the calendar and shows only the time row. Implies showTime.
hourFormat'12' | '24''12' adds an AM/PM toggle; '24' doesn't. Unset, it follows locale (or the runtime default) through Intl's hour12 resolution.
minuteStepnumber1Minute increment for the arrow-key and stepper-button adjustments.
uiPartial<Record<'root' | 'input' | 'positioner' | 'panel' | 'header' | 'navButton' | 'label' | 'weekdays' | 'weekday' | 'grid' | 'cell' | 'time' | 'footer' | 'icon', UiPartValue>>Class and style overrides for each part.
modelValueDate | CalendarRange | nullnullSelected date, or { start, end } in range mode.
openbooleanfalseWhether the panel is open.

Events

NameTypeDescription
update:modelValue(value: Date | CalendarRange | null)Fires when modelValue changes (v-model).
open-change(value: boolean, details: PopoverOpenChangeDetails)Fires when a close is requested; call details.cancel() to keep the panel open.
update:open(value: boolean)Fires when open changes (v-model:open).
change(value: Date | CalendarRange | null)Fires when you pick a date, time or range endpoint, type one, or use Today or Clear.
month-change(value: Date)Fires when the calendar's displayed month changes.

Slots

NameTypeDescription
day{ date: Date; isCurrentMonth: boolean; isToday: boolean; isSelected: boolean; isDisabled: boolean; }Custom content inside each day cell, the same as Calendar's #day. The cell keeps its own click, keyboard and aria wiring.
label{ label: string; date: Date; level: CalendarView; }Custom content for the panel's month and year heading, the same as Calendar's #label.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
inputElHTMLInputElement | nullNative <input> element.
panelElHTMLElement | nullPanel element (null while closed).
positionerElHTMLElement | nullPositioning wrapper around the panel (null while closed).
placementPlacementResolved placement after flipping, e.g. 'bottom-start'.
positionerStyleRecord<string, string>Computed position styles applied to the positioner.
isClosingbooleantrue while a beforeClose close is pending.
open() => voidOpens the panel unless disabled.
close() => voidCloses the panel, running @open-change and beforeClose first.
cancelClose() => voidCancels a close pending in beforeClose and keeps the panel open.

Motion New

DatePicker's panel: values or hooks for its parts, like Popover's. valueSwap: false shows a picked date without its crossfade.

<DatePicker
  :motion="{
    initial: { panel: { opacity: 0, y: 8, scale: 0.98 } },
    spring: { damping: 0.85, response: 0.35 },
  }"
/>
NameTypeDescription
initialexitpositionerpanelSets 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.
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 Combobox pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
A letterA digitSpaceTypes a date into the input.
ArrowDownOpens the calendar and focuses the selected day, or today.
EnterCommits the typed date, or opens or closes the calendar when nothing was typed.
EscapeCloses the calendar, or else undoes what you typed in the input.
ArrowLeftArrowRightArrowUpArrowDownMoves focus by a day or a week in the calendar.
HomeEndPageUpPageDownMoves focus by week edge or month in the calendar, as in Calendar.
EnterSpaceSelects the focused day and closes the calendar.
ArrowUpArrowDownSteps the focused hour or minute field.
HomeEndSets the focused hour or minute field to its lowest or highest value.
EnterCloses the calendar from the hour or minute field.
  • The input has role="combobox", aria-haspopup="dialog", aria-expanded and aria-controls. It reads typed dates in the locale’s order, or as yyyy-mm-dd. Enter or leaving the field commits; an entry that doesn’t read keeps the last value and sets aria-invalid.
  • It opens on click, ArrowDown, Enter or the calendar button, not on focus. A click keeps focus in the input for typing; the keys and the button move it to the calendar, and closing returns it to the input. The button is named “Choose date” and is out of the tab order.
  • The panel is a non-modal role="dialog" named “Choose date” (the datePicker.chooseDate message). A range stays open until both ends are set, and showTime stays open for the time. The hour and minute fields are role="spinbutton" inputs.
  • Inside a Field, the label names the input and error sets aria-invalid. Without one, pass aria-label. Right to left, ArrowLeft and ArrowRight swap in the calendar.