Date picker
An inline calendar grid. Every date it holds is a plain local-time YYYY-MM-DD string and never a Date, so a value cannot shift a day across time zones.
Usage
Examples
Range
selection set to range makes the value a start and an end, the span under the pointer being previewed between the two clicks.
Multiple dates
selection set to multiple makes the value a list, a day already in it coming back out when it is clicked again.
Presets
The #footer slot is a strip under the grid, for actions or for the dates a reader reaches for most. The buttons in it write the model like any other control.
Disabled dates
disabledDates takes a list of days, or a function asked about one date at a time. A closed day stays visible, struck through, and reachable by keyboard.
Minimum and maximum
min and max bound the navigation as well as the choice, in every view.
Event dots
events draws up to three dots under a day. Each takes any CSS colour and a label, which is what assistive technology reads.
Adjacent days
showAdjacentDays fills the corners of the grid with the neighbouring months, greyed and inert. selectAdjacentDays makes them choosable as well, and picking one moves the calendar to its month.
Localization
locale decides the month and day names and the day the weeks start on, and takes precedence over the global locale. firstDayOfWeek overrides the day that locale would have chosen.
API
Props
| Prop | Type | Default |
|---|---|---|
selection | DatePickerSelection'single' | 'range' | 'multiple' | 'single' |
| What the reader is picking: a single date, a period between two dates, or any number of separate dates. It determines the shape of the value. | ||
locale | string | none |
| A BCP 47 locale, which decides the month and day names and the first day of the week. It takes precedence over the design system's global locale and falls back to it, which is why it has no literal default. | ||
firstDayOfWeek | number | none |
| Forces the day the weeks start on, 0 for Sunday through 6 for Saturday. Left out, the locale decides. | ||
min | string | none |
| The earliest selectable date, as an ISO string. Neither navigation nor selection goes back beyond it. | ||
max | string | none |
| The latest selectable date, as an ISO string. Neither navigation nor selection goes past it. | ||
disabledDates | DatePickerMatcher | none |
| Dates that cannot be chosen, given as a list of ISO strings or as a function. They stay visible, struck through, and can still be reached with the keyboard. | ||
showAdjacentDays | boolean | false |
| Also fills the empty corners of the grid with the greyed days of the neighbouring months. | ||
selectAdjacentDays | boolean | false |
| Lets those neighbouring days be clicked, which moves the calendar to their month. A clickable day has to be visible, so this implies showing them. | ||
events | DatePickerEvent[] | none |
| The events to mark, as up to three coloured dots under the day they fall on. | ||
disabled | boolean | false |
| Makes the whole calendar unusable: no date can be chosen, no month reached, and everything greys out through the colour tokens. | ||
readonly | boolean | false |
Shows what is selected without letting it be changed. The calendar can still be read and walked through, another month or another year, which is what separates it from disabled. | ||
label | string | none |
The accessible name of the whole picker, its header and its grid together. A range shown as two calendars side by side needs one each, or a screen reader announces the same group twice. It falls back to the dictionary, and a consumer aria-label wins. | ||
v-model | DatePickerValue | null |
What is selected, and its shape follows selection: an ISO string for a single date, a start and end pair for a period, an array for several. Nothing is selected to begin with. | ||
Events
| Event | Type |
|---|---|
select | [value: DatePickerValue] |
A date was chosen, with the value as it now stands. Chosen is not finished: a period or a list is still being built after it, which is why VTimePicker names its own end of a choice confirm. | |
Slots
| Slot | Type |
|---|---|
day | DatePickerDaySlotProps |
| Replaces the content of a day cell, to show a price or an availability under the number. It receives everything known about that day, including whether it belongs to the displayed month. | |
footer | {} |
| The strip under the grid, for actions such as Close or Save, or for preset dates. | |
Types
The types the tables above name, written as the library declares them. The ones carrying export can be imported from vectis-ui to type your own code; the others are the shape of what a slot hands out.
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[]
CSS variables
| Token | Value |
|---|---|
--vectis-control-size-date-picker-cell | 2.5rem |
--vectis-control-size-date-picker-day | var(--vectis-control-height-md) |
--vectis-control-size-date-picker-dot | 0.25rem |
--vectis-control-size-date-picker-nav-min | 5.375rem |