Vitral 0.2.18
Form

DatePicker

A date field you can type into or pick from a calendar, read in the locale's format, with a time of day if you want one.

Import

main.ts
import { DatePicker } from '@vitral/vue';

Basic

Format from the locale · value: null
<script setup lang="ts">import { DatePicker, Label, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const today = new Date();const start = new Date(today.getFullYear(), today.getMonth(), today.getDate());const plus = (days: number) => new Date(start.getFullYear(), start.getMonth(), start.getDate() + days); const date = ref<Date | null>(null);const iso = ref<Date | null>(plus(3)); const shown = (value: Date | null) => (value ? value.toDateString() : 'null');</script> <template>    <StackPanel orientation="horizontal" spacing="0.75rem" align="start" wrap>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="dp-basic">Date</Label>            <DatePicker id="dp-basic" v-model="date" placeholder="Pick a date" aria-describedby="dp-basic-hint" />            <small id="dp-basic-hint" style="color: var(--vt-text-muted-color)">Format from the locale · value: {{ shown(date) }}</small>        </StackPanel>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="dp-iso">ISO format, weeks from Monday</Label>            <DatePicker id="dp-iso" v-model="iso" date-format="yyyy-MM-dd" :first-day-of-week="1" />        </StackPanel>    </StackPanel></template>

Month and year

The month and the year in the calendar's title are buttons. The year opens a page of twenty years, a year opens its months, and a month opens its days, so a date decades away is three presses rather than hundreds of months paged through. The arrow keys move through either grid, PageUp and PageDown turn the page, and Escape goes back to the days.

Press the year, then the month · value: null
Months and years out of range cannot be chosen
Inline
SuMoTuWeThFrSa
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Value: Tue May 20 2008
<script setup lang="ts">import { DatePicker, Label, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const today = new Date(); const born = ref<Date | null>(null);const hired = ref<Date | null>(new Date(2019, 7, 12));const archive = ref<Date | null>(new Date(2008, 4, 20)); const shown = (value: Date | null) => (value ? value.toDateString() : 'null');</script> <template>    <StackPanel orientation="horizontal" spacing="0.75rem" align="start" wrap>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="dp-born">Date of birth</Label>            <DatePicker id="dp-born" v-model="born" :max-date="today" placeholder="Pick a date" aria-describedby="dp-born-hint" />            <small id="dp-born-hint" style="color: var(--vt-text-muted-color)">Press the year, then the month · value: {{ shown(born) }}</small>        </StackPanel>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="dp-hired">Hired, between 2015 and 2030</Label>            <DatePicker id="dp-hired" v-model="hired" :min-date="new Date(2015, 2, 1)" :max-date="new Date(2030, 9, 31)" aria-describedby="dp-hired-hint" />            <small id="dp-hired-hint" style="color: var(--vt-text-muted-color)">Months and years out of range cannot be chosen</small>        </StackPanel>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <span id="dp-archive-label">Inline</span>            <DatePicker v-model="archive" inline aria-labelledby="dp-archive-label" />            <small style="color: var(--vt-text-muted-color)">Value: {{ shown(archive) }}</small>        </StackPanel>    </StackPanel></template>

Without the month or the year grid

Both are on by default and each is a prop. `:year-picker="false"` leaves the year as text, for dates that belong to one year; `:month-picker="false"` leaves the month as text, and a year chosen from the grid keeps the month on show. With both off the title is only text and the calendar is paged a month at a time.

<script setup lang="ts">import { DatePicker, Label, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const year = new Date().getFullYear(); const term = ref<Date | null>(null);const founded = ref<Date | null>(null);const paged = ref<Date | null>(null);</script> <template>    <StackPanel orientation="horizontal" spacing="0.75rem" align="start" wrap>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="dp-term">Months only, within this school year</Label>            <DatePicker id="dp-term" v-model="term" :year-picker="false" :min-date="new Date(year, 1, 1)" :max-date="new Date(year, 11, 15)" placeholder="Pick a date" />        </StackPanel>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="dp-founded">Years only</Label>            <DatePicker id="dp-founded" v-model="founded" :month-picker="false" placeholder="Pick a date" />        </StackPanel>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="dp-paged">Neither: the title is only text</Label>            <DatePicker id="dp-paged" v-model="paged" :month-picker="false" :year-picker="false" placeholder="Pick a date" />        </StackPanel>    </StackPanel></template>

Typing into the format

A `date-format` of fixed width types into its own shape by default: `dd/MM/yyyy` gives `__/__/____`, digits only, the separators typed for you. Half a date is put back when the box is left, and one pasted without its zeros, as `1/2/2026`, is read as a date first. A format with a month name has no fixed width and is left free; `:mask="false"` frees any of them, and a mask of your own replaces the derived one.

<script setup lang="ts">import { DatePicker, Label, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const masked = ref<Date | null>(null);const free = ref<Date | null>(null);</script> <template>    <StackPanel orientation="horizontal" spacing="0.75rem" align="start" wrap>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="dp-typed">In the shape of the format</Label>            <DatePicker id="dp-typed" v-model="masked" />        </StackPanel>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="dp-free">Free, with mask off</Label>            <DatePicker id="dp-free" v-model="free" :mask="false" placeholder="Type a date" />        </StackPanel>    </StackPanel></template>

With a time

`show-time` adds a time field under the days. The box writes the time after the date and reads one typed there; choosing a day keeps the time already chosen and leaves the calendar open for it. `time-step` sets the minutes between the times listed, and any minute can still be typed. `min-time` and `max-time` keep every time inside the day you allow, the right-hand one here from 08:00 to 18:00.

Value: —
<script setup lang="ts">import { DatePicker, Label, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const meeting = ref<Date | null>(null);const shift = ref<Date | null>(null);</script> <template>    <StackPanel orientation="horizontal" spacing="0.75rem" align="start" wrap>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="dp-meeting">Meeting</Label>            <DatePicker id="dp-meeting" v-model="meeting" show-time placeholder="Pick a date and time" />            <small style="color: var(--vt-text-muted-color)">Value: {{ meeting ? meeting.toISOString() : '—' }}</small>        </StackPanel>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="dp-shift">Every quarter hour, 08:00 to 18:00</Label>            <DatePicker id="dp-shift" v-model="shift" show-time :time-step="15" :hour12="false" min-time="08:00" max-time="18:00" show-clear-button placeholder="Pick a date and time" />        </StackPanel>    </StackPanel></template>

Constraints

Only the next 30 days, no weekends, and two blocked days. Unselectable days are skipped by the keys and cannot be clicked or typed.

<script setup lang="ts">import { DatePicker, Label, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const today = new Date();const start = new Date(today.getFullYear(), today.getMonth(), today.getDate());const plus = (days: number) => new Date(start.getFullYear(), start.getMonth(), start.getDate() + days); const booking = ref<Date | null>(null);const holidays = [plus(4), plus(5)];</script> <template>    <StackPanel spacing="0.375rem" style="min-width: 16rem">        <Label for="dp-booking">Delivery</Label>        <DatePicker id="dp-booking" v-model="booking" :min-date="start" :max-date="plus(30)" :disabled-days="[0, 6]" :disabled-dates="holidays" placeholder="Choose a weekday" />    </StackPanel></template>

Inline

The calendar on its own, without the field.

Pick-up day
SuMoTuWeThFrSa
1234567
891011121314
15161718192021
22232425262728
293012345
6789101112
Value: Sat Nov 14 2026
Disabled
SuMoTuWeThFrSa
1234567
891011121314
15161718192021
22232425262728
293012345
6789101112
<script setup lang="ts">import { DatePicker, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const today = new Date();const start = new Date(today.getFullYear(), today.getMonth(), today.getDate());const plus = (days: number) => new Date(start.getFullYear(), start.getMonth(), start.getDate() + days); const inline = ref<Date | null>(plus(2));</script> <template>    <StackPanel orientation="horizontal" spacing="0.75rem" align="start" wrap>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <span id="dp-inline-label">Pick-up day</span>            <DatePicker v-model="inline" inline show-today-button show-clear-button aria-labelledby="dp-inline-label" />            <small style="color: var(--vt-text-muted-color)">Value: {{ inline ? inline.toDateString() : 'null' }}</small>        </StackPanel>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <span id="dp-inline-disabled">Disabled</span>            <DatePicker :model-value="plus(1)" inline disabled aria-labelledby="dp-inline-disabled" />        </StackPanel>    </StackPanel></template>

Sizes, variants and states

<script setup lang="ts">import { DatePicker } from '@vitral/vue'; const today = new Date();const start = new Date(today.getFullYear(), today.getMonth(), today.getDate());</script> <template>    <DatePicker size="small" placeholder="Small" aria-label="Small" />    <DatePicker placeholder="Normal" aria-label="Normal" />    <DatePicker size="large" placeholder="Large" aria-label="Large" />    <DatePicker variant="filled" placeholder="Filled" aria-label="Filled" />    <DatePicker invalid placeholder="Invalid" aria-label="Invalid" />    <DatePicker :model-value="start" disabled aria-label="Disabled" />    <DatePicker :model-value="start" readonly aria-label="Read only" /></template>

Fluid

<script setup lang="ts">import { DatePicker } from '@vitral/vue';</script> <template>    <DatePicker fluid placeholder="Fills its container" aria-label="Fluid" /></template>

API

Read from packages/vue/src/components/DatePicker/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
dateFormat stringA `formatDate` pattern (`yyyy yy MMMM MMM MM M dd d`); defaults to the locale's `dateFormat`.
minDate Date | nullThe earliest selectable day.
maxDate Date | nullThe latest selectable day.
disabledDates Date[]Days that cannot be chosen.
disabledDays number[]Weekdays that cannot be chosen, 0 = Sunday.
showTodayButton booleanA footer button that selects today.
showClearButton booleanA footer button that empties the value.
monthPicker booleanWhether the month in the calendar's title opens a grid of the twelve months. On by default; off, the month is only text and is reached by paging.
yearPicker booleanWhether the year in the calendar's title opens a grid of years. On by default; off, the year is only text. With the month grid off as well, the calendar can only be paged a month at a time.
showTime booleanTake a time of day with the date. The calendar gains a time field under its days, the text box writes the time after the date and reads one typed there, and choosing a day keeps the calendar open for the time. Off by default.
timeStep numberMinutes between the times the time field offers. Defaults to 30; any minute can still be typed.
minTime number | string | nullThe earliest time of day, as minutes past midnight or `'08:00'`. A time chosen or typed before it is moved up to it.
maxTime number | string | nullThe latest time of day, likewise.
hour12 booleanForce twelve- or twenty-four-hour time; defaults to what the locale writes.
mask boolean | MaskPropWhether the text box types into the shape the date is written in. On by default: a `dateFormat` of fixed width (`dd/MM/yyyy`, `yyyy-MM-dd`, with a twenty-four-hour time after it) gives `99/99/9999`, and a format with a month name or a day without its zero gives none. `false` leaves the box free; a mask of your own, as InputMask takes, replaces the derived one.
firstDayOfWeek number0 = Sunday; defaults to the locale's `firstDayOfWeek`.
placeholder string—
inline booleanShow the calendar in place, without a text box or popup.
size Size—
variant InputVariantDefaults to the plugin's `inputVariant`.
invalid boolean—
disabled boolean—
readonly boolean—
fluid boolean—
placement OverlayPlacement—
appendTo string`'body'` (the default), `'self'` to render in place, or a selector.

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Emits

EventPayloadDescription
dateSelect date: DateA day was chosen in the calendar, or typed and committed; with `showTime`, also a time.
clear ——
show ——
hide ——
monthChange event: DatePickerMonthChangeEvent—
focus event: FocusEvent—
blur event: FocusEvent—

Slots

NameSlot propsDescription
date (props: DatePickerDateSlotProps)The content of one day cell.
footer —Extra content in the calendar's footer.
dropdownicon —The calendar button's icon.