Champ de date
VDateInput associe un champ de date localisé à VDatePicker. Il accepte une date, une période ou plusieurs dates.
Utilisation
<script setup lang="ts">
import { ref } from 'vue'
import { VDateInput } from 'vectis-ui'
const date = ref<string | null>(null)
</script>
<template>
<VDateInput v-model="date" label="Start date" show-picker />
</template>Exemples
Libellé, aide et icône
Nommez le champ avec label et ajoutez une aide avec hint.
<script setup lang="ts">
import { ref } from 'vue'
import { VDateInput } from 'vectis-ui'
import { calendar_today as calendarToday, schedule, search } from 'vectis-ui/icons'
const start = ref<string | null>('2026-06-10')
const deadline = ref<string | null>(null)
</script>
<template>
<div class="column">
<VDateInput
v-model="start"
label="Start date"
hint="Type it or pick it from the calendar"
show-picker
:picker-icon="calendarToday"
/>
<VDateInput
v-model="deadline"
label="Deadline"
hint="The calendar is the only way in"
mode="picker"
:picker-icon="schedule"
/>
<VDateInput
v-model="start"
label="Filter by date"
hint="An icon at the start, a spinner at the end while something loads"
:icon-start="search"
loading
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Tailles
size définit la taille du champ.
<script setup lang="ts">
import { ref } from 'vue'
import { VDateInput } from 'vectis-ui'
const rows = ref(
(['sm', 'md', 'lg'] as const).map((size) => ({
key: size,
size,
label: size,
date: '2026-06-10' as string | null,
})),
)
</script>
<template>
<div class="column">
<VDateInput
v-for="row in rows"
:key="row.key"
v-model="row.date"
:size="row.size"
:label="row.label"
show-picker
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Modes
input accepte une date numérique localisée. showPicker y ajoute un calendrier. picker utilise uniquement le calendrier ; les sélections de période et de dates multiples imposent ce mode.
<script setup lang="ts">
import { ref } from 'vue'
import { VDateInput } from 'vectis-ui'
const typed = ref<string | null>('2026-06-10')
const withPicker = ref<string | null>('2026-06-10')
const readOnly = ref<string | null>('2026-06-10')
</script>
<template>
<div class="column">
<VDateInput
v-model="typed"
label="Typed, the default"
hint="No icon, no panel: the field is the whole control"
/>
<VDateInput
v-model="withPicker"
show-picker
label="Typed, with the calendar"
hint="showPicker adds the icon and opens the panel on focus"
/>
<VDateInput
v-model="readOnly"
mode="picker"
label="Read-only"
hint="Nothing can be typed, so the calendar is the only way in"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Période
selection="range" utilise un modèle { start, end }. Chaque borne est une date ISO ou null.
<script setup lang="ts">
import { ref } from 'vue'
import { VDateInput, type DatePickerRange } from 'vectis-ui'
const period = ref<DatePickerRange>({ start: '2026-06-19', end: '2026-06-26' })
</script>
<template>
<div class="column">
<VDateInput
v-model="period"
selection="range"
label="Period"
hint="Pick the first day, then the last. Typing falls back to read-only here."
clearable
/>
<output class="value" aria-label="Chosen period">
{{ period.start ?? 'none' }} to {{ period.end ?? 'none' }}
</output>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-3);
max-inline-size: 26rem;
}
.value {
font-family: var(--vectis-text-family-code);
font-size: var(--vectis-text-body-sm-size);
color: var(--vectis-color-text-muted);
}
</style>Dates multiples
selection="multiple" utilise un tableau de dates ISO. Sélectionnez à nouveau une date pour la retirer.
<script setup lang="ts">
import { ref } from 'vue'
import { VDateInput } from 'vectis-ui'
const dates = ref<string[]>(['2026-06-05', '2026-06-12'])
</script>
<template>
<div class="column">
<VDateInput
v-model="dates"
selection="multiple"
label="Dates"
hint="Click a day to add it, click it again to take it back"
clearable
/>
<output class="value" aria-label="Chosen dates">{{ dates.join(', ') || 'none' }}</output>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-3);
max-inline-size: 26rem;
}
.value {
font-family: var(--vectis-text-family-code);
font-size: var(--vectis-text-body-sm-size);
color: var(--vectis-color-text-muted);
}
</style>Raccourcis
Ajoutez des dates prédéfinies dans footer. Son rappel close ferme le panneau.
<script setup lang="ts">
import { ref } from 'vue'
import { VButton, VDateInput } from 'vectis-ui'
const date = ref<string | null>(null)
/* Read today's local date in the click handler to avoid a prerendered value. */
function inDays(offset: number, close: () => void) {
const day = new Date()
day.setDate(day.getDate() + offset)
const month = String(day.getMonth() + 1).padStart(2, '0')
date.value = `${day.getFullYear()}-${month}-${String(day.getDate()).padStart(2, '0')}`
close()
}
</script>
<template>
<div class="column">
<VDateInput v-model="date" mode="picker" label="Due date" clearable>
<template #footer="{ close }">
<VButton variant="ghost" tone="neutral" size="sm" @click="inDays(0, close)">Today</VButton>
<VButton variant="ghost" tone="neutral" size="sm" @click="inDays(1, close)">
Tomorrow
</VButton>
<VButton variant="ghost" tone="neutral" size="sm" @click="inDays(7, close)">
In a week
</VButton>
</template>
</VDateInput>
</div>
</template>
<style scoped>
.column {
max-inline-size: 26rem;
}
</style>Bornes et jours fermés
min et max limitent la sélection et la navigation. Excluez certaines dates avec disabledDates.
<script setup lang="ts">
import { ref } from 'vue'
import { VDateInput } from 'vectis-ui'
const booking = ref<string | null>('2026-06-15')
const appointment = ref<string | null>('2026-06-16')
function isWeekend(iso: string) {
const day = new Date(`${iso}T00:00:00`).getDay()
return day === 0 || day === 6
}
</script>
<template>
<div class="column">
<VDateInput
v-model="booking"
min="2026-06-05"
max="2026-06-24"
label="Booking"
hint="Between 5 and 24 June 2026: the arrows stop at the bounds"
show-picker
/>
<VDateInput
v-model="appointment"
:disabled-dates="isWeekend"
label="Appointment"
hint="Weekends are struck through: still reachable, never choosable"
show-picker
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Pastilles
events ajoute trois points au maximum par jour. Les libellés des événements font partie du nom accessible du jour.
<script setup lang="ts">
import { ref } from 'vue'
import { VDateInput, type DatePickerEvent } from 'vectis-ui'
const date = ref<string | null>('2026-06-10')
const events: DatePickerEvent[] = [
{ date: '2026-06-10', label: 'Kick-off' },
{ date: '2026-06-18', color: 'var(--vectis-color-danger)', label: 'Deadline' },
{ date: '2026-06-18', color: 'var(--vectis-color-warning)', label: 'Review' },
{ date: '2026-06-24', color: 'var(--vectis-color-success)', label: 'Release' },
]
</script>
<template>
<div class="column">
<VDateInput
v-model="date"
:events="events"
mode="picker"
label="Sprint date"
hint="Open the calendar: June has four marked days"
/>
</div>
</template>
<style scoped>
.column {
max-inline-size: 26rem;
}
</style>Cellules de jour personnalisées
Personnalisez le contenu des cellules avec day, à partir de leur date et de leur état de sélection.
<script setup lang="ts">
import { ref } from 'vue'
import { VDateInput } from 'vectis-ui'
const night = ref<string | null>('2026-06-15')
/* Derive prices from dates so server and client render the same values. */
function priceFor(iso: string) {
return 80 + ((Number(iso.slice(-2)) * 7) % 60)
}
</script>
<template>
<div class="column">
<VDateInput
v-model="night"
mode="picker"
min="2026-06-05"
max="2026-06-24"
label="Night"
hint="The slot replaces the day number, so what it draws follows the selection"
>
<template #day="{ day, iso, inMonth, disabled }">
<span class="number">{{ day }}</span>
<small v-if="inMonth && !disabled" class="price">€{{ priceFor(iso) }}</small>
</template>
</VDateInput>
</div>
</template>
<style scoped>
.column {
max-inline-size: 26rem;
}
.number {
line-height: 1;
}
/* Inherit the selected day's foreground colour to preserve contrast. */
.price {
font-size: var(--vectis-text-caption-size);
line-height: 1;
color: color-mix(in oklab, currentcolor 65%, transparent);
}
</style>Effacement
clearable ajoute un bouton pour effacer la sélection.
<script setup lang="ts">
import { ref } from 'vue'
import { VDateInput } from 'vectis-ui'
const withCross = ref<string | null>('2026-06-10')
const withoutCross = ref<string | null>('2026-06-10')
</script>
<template>
<div class="column">
<VDateInput
v-model="withCross"
clearable
show-picker
label="Clearable"
hint="The cross sits to the left of the calendar icon, never in its place"
/>
<VDateInput
v-model="withoutCross"
show-picker
label="Not clearable, the default"
hint="Emptying the field is then the reader's own business"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Jours adjacents
showAdjacentDays affiche les jours voisins. selectAdjacentDays permet aussi de les choisir et ouvre leur mois.
<script setup lang="ts">
import { ref } from 'vue'
import { VDateInput } from 'vectis-ui'
const hidden = ref<string | null>('2026-06-10')
const shown = ref<string | null>('2026-06-10')
const selectable = ref<string | null>('2026-06-10')
</script>
<template>
<div class="column">
<VDateInput
v-model="hidden"
mode="picker"
label="Hidden, the default"
hint="The grid starts and ends on the month itself"
/>
<VDateInput
v-model="shown"
show-adjacent-days
mode="picker"
label="Shown"
hint="The corners are filled with the neighbouring months, greyed and inert"
/>
<VDateInput
v-model="selectable"
select-adjacent-days
mode="picker"
label="Shown and choosable"
hint="Choosing one moves the calendar to its month"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>États
readonly empêche la saisie, la sélection et l’effacement tout en conservant le focus. loading affiche un indicateur sans désactiver le champ.
<script setup lang="ts">
import { ref } from 'vue'
import { VDateInput } from 'vectis-ui'
const invalid = ref<string | null>('2026-06-10')
</script>
<template>
<div class="column">
<VDateInput
v-model="invalid"
invalid
show-picker
label="Invalid"
hint="For a rule the browser cannot check by itself"
/>
<VDateInput
model-value="2026-06-10"
disabled
show-picker
label="Disabled, with a value"
hint="Greyed through the colour tokens, and the panel can no longer be opened"
/>
<VDateInput model-value="2026-06-10" disabled mode="picker" label="Disabled, picker only" />
<VDateInput
model-value="2026-06-10"
readonly
show-picker
clearable
label="Read-only"
hint="No typing, no calendar, no clear cross"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Localisation
locale définit les noms et l’ordre des éléments de date. displayFormat personnalise l’affichage en mode calendrier ; il ne modifie pas le masque de saisie.
<script setup lang="ts">
import { ref } from 'vue'
import { VDateInput } from 'vectis-ui'
const locales = ref([
{ tag: 'en-US', label: 'en-US, month first, weeks from Sunday', date: '2026-06-10' },
{ tag: 'en-GB', label: 'en-GB, day first, weeks from Monday', date: '2026-06-10' },
{ tag: 'de-DE', label: 'de-DE, dots for separators', date: '2026-06-10' },
{ tag: 'ja-JP', label: 'ja-JP, year first', date: '2026-06-10' },
])
const written = ref<string | null>('2026-06-10')
</script>
<template>
<div class="column">
<VDateInput
v-for="locale in locales"
:key="locale.tag"
v-model="locale.date"
:locale="locale.tag"
:label="locale.label"
show-picker
/>
<VDateInput
v-model="written"
locale="fr-FR"
mode="picker"
:display-format="{ dateStyle: 'full' }"
label="fr-FR, written out in full"
hint="displayFormat is an Intl option bag, and it only applies where nothing is typed"
/>
</div>
</template>
<style scoped>
.column {
display: flex;
flex-direction: column;
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>Placement
placement définit la position souhaitée du calendrier.
<script setup lang="ts">
import { ref } from 'vue'
import { VDateInput } from 'vectis-ui'
const placements = ['bottom-start', 'bottom-end', 'top-start', 'top-end'] as const
const dates = ref<Record<string, string | null>>({
'bottom-start': '2026-06-10',
'bottom-end': '2026-06-10',
'top-start': '2026-06-10',
'top-end': '2026-06-10',
})
</script>
<template>
<div class="grid">
<VDateInput
v-for="placement in placements"
:key="placement"
v-model="dates[placement]"
:placement="placement"
:label="placement"
mode="picker"
/>
</div>
</template>
<style scoped>
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
gap: var(--vectis-space-5);
max-inline-size: 26rem;
}
</style>API
Props
Événements
Slots
Types
Types utilisés dans les tables d’API. Importez les types exportés depuis vectis-ui.
export interface BuiltinIcon {
name: string
paths: readonly [string] | readonly [string, string]
}export interface DatePickerDaySlotProps {
iso: string
day: number
inMonth: boolean
disabled: boolean
selected: boolean
today: boolean
inRange: boolean
events: DatePickerEvent[]
}export interface DatePickerEvent {
date: string
color?: string
label?: string
}export type DatePickerMatcher = string[] | ((iso: string) => boolean)
export interface DatePickerRange {
start: string | null
end: string | null
}export type DatePickerValue = string | null | DatePickerRange | string[]
export type IconRender =
| { path: string; viewBox?: string }
| { component: Component; props?: Record<string, unknown> }
| { src: string }
| { text: string; class?: string }
| { class: string }export type IconSource = string | BuiltinIcon | IconRender