Date Field
A field with one segment for each part of a date, such as the month, the day and the year.
<script setup lang="ts">
import { useId } from 'vue';
import { DateField } from '@vase-ui/vue/date-field';
import styles from './index.module.css';
const id = useId();
</script>
<template>
<div :class="styles.Field">
<label :for="id" :class="styles.Label">Departure date</label>
<DateField.Root :id="id" locale="en-US" :class="styles.Root">
<DateField.Input :class="styles.Input">
<template #segment="{ segment }">
<DateField.Segment v-if="segment.editable" :segment="segment" :class="styles.Segment" />
<DateField.Literal v-else :segment="segment" :class="styles.Literal" />
</template>
</DateField.Input>
</DateField.Root>
</div>
</template>.Field {
display: flex;
flex-direction: column;
align-items: start;
gap: 0.25rem;
}
.Label {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 700;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Root {
display: flex;
align-items: center;
}
.Input {
box-sizing: border-box;
display: flex;
align-items: center;
height: 2rem;
padding: 0 0.5rem;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
font-variant-numeric: tabular-nums;
background-color: white;
color: oklch(14.5% 0 0deg);
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&:focus-within {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Segment {
/* The box follows the text. A browser with no `field-sizing` keeps the width of `size`. */
field-sizing: content;
margin: 0;
padding: 0 0.125rem;
border: 0;
border-radius: 0;
outline: 0;
font: inherit;
text-align: center;
caret-color: transparent;
background-color: transparent;
color: inherit;
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
&::placeholder {
color: oklch(70.8% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(43.9% 0 0deg);
}
}
}
}
.Literal {
color: oklch(43.9% 0 0deg);
white-space: pre;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Value {
margin: 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}<script setup lang="ts">
import { useId } from 'vue';
import { DateField } from '@vase-ui/vue/date-field';
const id = useId();
</script>
<template>
<div class="flex flex-col items-start gap-1">
<label :for="id" class="text-sm font-bold text-neutral-950 dark:text-white"
>Departure date</label
>
<DateField.Root :id="id" locale="en-US" class="flex items-center">
<DateField.Input
class="flex h-8 items-center border border-neutral-950 bg-white px-2 text-sm font-normal text-neutral-950 tabular-nums any-pointer-coarse:text-base focus-within:outline-2 focus-within:-outline-offset-1 focus-within:outline-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white dark:focus-within:outline-white"
>
<template #segment="{ segment }">
<DateField.Segment
v-if="segment.editable"
:segment="segment"
class="field-sizing-content px-0.5 text-center caret-transparent outline-0 placeholder:text-neutral-500 focus:bg-neutral-950 focus:text-white focus:placeholder:text-neutral-400 dark:placeholder:text-neutral-400 dark:focus:bg-white dark:focus:text-neutral-950 dark:focus:placeholder:text-neutral-600"
/>
<DateField.Literal
v-else
:segment="segment"
class="whitespace-pre text-neutral-600 dark:text-neutral-400"
/>
</template>
</DateField.Input>
</DateField.Root>
</div>
</template>Usage guidelines
- The field needs
Temporal: Load aTemporalpolyfill for an engine that has none, such as Safari and Node.js 24. Use TypeScript 6.0, or setskipLibCheck. See Dates and times. - Form controls must have an accessible name: Put the field in a
Fieldwith aField.Label, giveDateField.Rootanaria-labelor anaria-labelledby, or point a<label for>at theidof the root. A<label for>names the field only after the mount, so the server HTML has no name for it. See the forms guide. - The clear button must have a name:
DateField.Clearhas no content and no name of its own. Give it content and anaria-labelin the language of the page.
Anatomy
Import the component and assemble its parts:
<script setup lang="ts">
import { DateField } from '@vase-ui/vue/date-field';
</script>
<template>
<DateField.Root>
<DateField.Input>
<template #segment="{ segment }">
<DateField.Segment v-if="segment.editable" :segment="segment" />
<DateField.Literal v-else :segment="segment" />
</template>
</DateField.Input>
<DateField.Clear aria-label="Clear the date">×</DateField.Clear>
</DateField.Root>
</template>Examples
Date and time
A Temporal.PlainDateTime value adds the hour and the minute. A locale with a 12-hour cycle adds the day period. Set granularity to second to add the seconds.
Value: 2026-11-14T15:04:00
<script setup lang="ts">
import { shallowRef, useId } from 'vue';
import { DateField } from '@vase-ui/vue/date-field';
import styles from './index.module.css';
const id = useId();
const value = shallowRef<Temporal.PlainDateTime | null>(
Temporal.PlainDateTime.from('2026-11-14T15:04'),
);
</script>
<template>
<div :class="styles.Field">
<label :for="id" :class="styles.Label">Appointment</label>
<DateField.Root :id="id" v-model="value" locale="en-US" :class="styles.Root">
<DateField.Input :class="styles.Input">
<template #segment="{ segment }">
<DateField.Segment v-if="segment.editable" :segment="segment" :class="styles.Segment" />
<DateField.Literal v-else :segment="segment" :class="styles.Literal" />
</template>
</DateField.Input>
</DateField.Root>
<p :class="styles.Value">Value: {{ value?.toString() ?? 'none' }}</p>
</div>
</template>.Field {
display: flex;
flex-direction: column;
align-items: start;
gap: 0.25rem;
}
.Label {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 700;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Root {
display: flex;
align-items: center;
}
.Input {
box-sizing: border-box;
display: flex;
align-items: center;
height: 2rem;
padding: 0 0.5rem;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
font-variant-numeric: tabular-nums;
background-color: white;
color: oklch(14.5% 0 0deg);
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&:focus-within {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Segment {
/* The box follows the text. A browser with no `field-sizing` keeps the width of `size`. */
field-sizing: content;
margin: 0;
padding: 0 0.125rem;
border: 0;
border-radius: 0;
outline: 0;
font: inherit;
text-align: center;
caret-color: transparent;
background-color: transparent;
color: inherit;
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
&::placeholder {
color: oklch(70.8% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(43.9% 0 0deg);
}
}
}
}
.Literal {
color: oklch(43.9% 0 0deg);
white-space: pre;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Value {
margin: 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}<script setup lang="ts">
import { shallowRef, useId } from 'vue';
import { DateField } from '@vase-ui/vue/date-field';
const id = useId();
const value = shallowRef<Temporal.PlainDateTime | null>(
Temporal.PlainDateTime.from('2026-11-14T15:04'),
);
</script>
<template>
<div class="flex flex-col items-start gap-1">
<label :for="id" class="text-sm font-bold text-neutral-950 dark:text-white">Appointment</label>
<DateField.Root :id="id" v-model="value" locale="en-US" class="flex items-center">
<DateField.Input
class="flex h-8 items-center border border-neutral-950 bg-white px-2 text-sm font-normal text-neutral-950 tabular-nums any-pointer-coarse:text-base focus-within:outline-2 focus-within:-outline-offset-1 focus-within:outline-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white dark:focus-within:outline-white"
>
<template #segment="{ segment }">
<DateField.Segment
v-if="segment.editable"
:segment="segment"
class="field-sizing-content px-0.5 text-center caret-transparent outline-0 placeholder:text-neutral-500 focus:bg-neutral-950 focus:text-white focus:placeholder:text-neutral-400 dark:placeholder:text-neutral-400 dark:focus:bg-white dark:focus:text-neutral-950 dark:focus:placeholder:text-neutral-600"
/>
<DateField.Literal
v-else
:segment="segment"
class="whitespace-pre text-neutral-600 dark:text-neutral-400"
/>
</template>
</DateField.Input>
</DateField.Root>
<p class="text-sm text-neutral-600 dark:text-neutral-400">
Value: {{ value?.toString() ?? 'none' }}
</p>
</div>
</template>Time zones
A Temporal.ZonedDateTime value shows the name of its time zone. Set hideTimeZone to hide the name. The field keeps the time zone in each value that it gives.
Value: 2026-11-14T15:04:00+09:00[Asia/Tokyo]
<script setup lang="ts">
import { shallowRef, useId } from 'vue';
import { DateField } from '@vase-ui/vue/date-field';
import styles from './index.module.css';
const id = useId();
const value = shallowRef<Temporal.ZonedDateTime | null>(
Temporal.ZonedDateTime.from('2026-11-14T15:04[Asia/Tokyo]'),
);
</script>
<template>
<div :class="styles.Field">
<label :for="id" :class="styles.Label">Flight departs</label>
<DateField.Root :id="id" v-model="value" locale="en-US" :class="styles.Root">
<DateField.Input :class="styles.Input">
<template #segment="{ segment }">
<DateField.Segment v-if="segment.editable" :segment="segment" :class="styles.Segment" />
<DateField.Literal v-else :segment="segment" :class="styles.Literal" />
</template>
</DateField.Input>
</DateField.Root>
<p :class="styles.Value">Value: {{ value?.toString() ?? 'none' }}</p>
</div>
</template>.Field {
display: flex;
flex-direction: column;
align-items: start;
gap: 0.25rem;
}
.Label {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 700;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Root {
display: flex;
align-items: center;
}
.Input {
box-sizing: border-box;
display: flex;
align-items: center;
height: 2rem;
padding: 0 0.5rem;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
font-variant-numeric: tabular-nums;
background-color: white;
color: oklch(14.5% 0 0deg);
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&:focus-within {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Segment {
/* The box follows the text. A browser with no `field-sizing` keeps the width of `size`. */
field-sizing: content;
margin: 0;
padding: 0 0.125rem;
border: 0;
border-radius: 0;
outline: 0;
font: inherit;
text-align: center;
caret-color: transparent;
background-color: transparent;
color: inherit;
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
&::placeholder {
color: oklch(70.8% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(43.9% 0 0deg);
}
}
}
}
.Literal {
color: oklch(43.9% 0 0deg);
white-space: pre;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Value {
margin: 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}<script setup lang="ts">
import { shallowRef, useId } from 'vue';
import { DateField } from '@vase-ui/vue/date-field';
const id = useId();
const value = shallowRef<Temporal.ZonedDateTime | null>(
Temporal.ZonedDateTime.from('2026-11-14T15:04[Asia/Tokyo]'),
);
</script>
<template>
<div class="flex flex-col items-start gap-1">
<label :for="id" class="text-sm font-bold text-neutral-950 dark:text-white"
>Flight departs</label
>
<DateField.Root :id="id" v-model="value" locale="en-US" class="flex items-center">
<DateField.Input
class="flex h-8 items-center border border-neutral-950 bg-white px-2 text-sm font-normal text-neutral-950 tabular-nums any-pointer-coarse:text-base focus-within:outline-2 focus-within:-outline-offset-1 focus-within:outline-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white dark:focus-within:outline-white"
>
<template #segment="{ segment }">
<DateField.Segment
v-if="segment.editable"
:segment="segment"
class="field-sizing-content px-0.5 text-center caret-transparent outline-0 placeholder:text-neutral-500 focus:bg-neutral-950 focus:text-white focus:placeholder:text-neutral-400 dark:placeholder:text-neutral-400 dark:focus:bg-white dark:focus:text-neutral-950 dark:focus:placeholder:text-neutral-600"
/>
<DateField.Literal
v-else
:segment="segment"
class="whitespace-pre text-neutral-600 dark:text-neutral-400"
/>
</template>
</DateField.Input>
</DateField.Root>
<p class="text-sm text-neutral-600 dark:text-neutral-400">
Value: {{ value?.toString() ?? 'none' }}
</p>
</div>
</template>Month and year
A Temporal.PlainYearMonth value has no day. A Temporal.PlainDate with the granularity month shows the same two segments, and keeps its day.
Value: 2026-11
<script setup lang="ts">
import { shallowRef, useId } from 'vue';
import { DateField } from '@vase-ui/vue/date-field';
import styles from './index.module.css';
const id = useId();
const value = shallowRef<Temporal.PlainYearMonth | null>(Temporal.PlainYearMonth.from('2026-11'));
</script>
<template>
<div :class="styles.Field">
<label :for="id" :class="styles.Label">Card expires</label>
<DateField.Root :id="id" v-model="value" locale="en-US" :class="styles.Root">
<DateField.Input :class="styles.Input">
<template #segment="{ segment }">
<DateField.Segment v-if="segment.editable" :segment="segment" :class="styles.Segment" />
<DateField.Literal v-else :segment="segment" :class="styles.Literal" />
</template>
</DateField.Input>
</DateField.Root>
<p :class="styles.Value">Value: {{ value?.toString() ?? 'none' }}</p>
</div>
</template>.Field {
display: flex;
flex-direction: column;
align-items: start;
gap: 0.25rem;
}
.Label {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 700;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Root {
display: flex;
align-items: center;
}
.Input {
box-sizing: border-box;
display: flex;
align-items: center;
height: 2rem;
padding: 0 0.5rem;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
font-variant-numeric: tabular-nums;
background-color: white;
color: oklch(14.5% 0 0deg);
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&:focus-within {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Segment {
/* The box follows the text. A browser with no `field-sizing` keeps the width of `size`. */
field-sizing: content;
margin: 0;
padding: 0 0.125rem;
border: 0;
border-radius: 0;
outline: 0;
font: inherit;
text-align: center;
caret-color: transparent;
background-color: transparent;
color: inherit;
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
&::placeholder {
color: oklch(70.8% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(43.9% 0 0deg);
}
}
}
}
.Literal {
color: oklch(43.9% 0 0deg);
white-space: pre;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Value {
margin: 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}<script setup lang="ts">
import { shallowRef, useId } from 'vue';
import { DateField } from '@vase-ui/vue/date-field';
const id = useId();
const value = shallowRef<Temporal.PlainYearMonth | null>(Temporal.PlainYearMonth.from('2026-11'));
</script>
<template>
<div class="flex flex-col items-start gap-1">
<label :for="id" class="text-sm font-bold text-neutral-950 dark:text-white">Card expires</label>
<DateField.Root :id="id" v-model="value" locale="en-US" class="flex items-center">
<DateField.Input
class="flex h-8 items-center border border-neutral-950 bg-white px-2 text-sm font-normal text-neutral-950 tabular-nums any-pointer-coarse:text-base focus-within:outline-2 focus-within:-outline-offset-1 focus-within:outline-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white dark:focus-within:outline-white"
>
<template #segment="{ segment }">
<DateField.Segment
v-if="segment.editable"
:segment="segment"
class="field-sizing-content px-0.5 text-center caret-transparent outline-0 placeholder:text-neutral-500 focus:bg-neutral-950 focus:text-white focus:placeholder:text-neutral-400 dark:placeholder:text-neutral-400 dark:focus:bg-white dark:focus:text-neutral-950 dark:focus:placeholder:text-neutral-600"
/>
<DateField.Literal
v-else
:segment="segment"
class="whitespace-pre text-neutral-600 dark:text-neutral-400"
/>
</template>
</DateField.Input>
</DateField.Root>
<p class="text-sm text-neutral-600 dark:text-neutral-400">
Value: {{ value?.toString() ?? 'none' }}
</p>
</div>
</template>Validation in a Field
Put the field in a Field to show the errors of its validation. The form input has the type of the value:
| Value | Form input | Form text | Checks |
|---|---|---|---|
Temporal.PlainDate | date | 2026-11-14 | Native |
Temporal.PlainDateTime | datetime-local | 2026-11-14T15:04 | Native |
Temporal.ZonedDateTime | text | 2026-11-14T15:04+09:00[Asia/Tokyo] | required native, the limits by the field |
Temporal.PlainYearMonth | text | 2026-11 | required native, the limits by the field |
A Temporal.PlainDate in min or max limits whole days. A limit with a time also limits the time of a field that shows a time. A field that shows no time compares days. A limit in a time zone counts as its local time in the zone of a zoned value. A year and month is in the limits when one of its days is.
The field also finds the failures that the type of its form input cannot find. It sets each one as a custom error of the form input, with the message of the browser. Field.Error with match reads them as native failures:
badInput: some segments are empty, as in a native date input.rangeUnderflowandrangeOverflow: a limit, for each kind of value.customError: a date thatunavailableDatesmatches. Give the reason in the content of<Field.Error match="customError">.
Outside a Field, inputElement.validity.customError is true for each of these failures, and validationMessage says which.
Choose a weekday in November 2026.
<script setup lang="ts">
import { DateField } from '@vase-ui/vue/date-field';
import { Field } from '@vase-ui/vue/field';
import styles from './index.module.css';
const defaultValue = Temporal.PlainDate.from('2026-12-01');
const minDate = Temporal.PlainDate.from('2026-11-01');
const maxDate = Temporal.PlainDate.from('2026-11-30');
// Saturday and Sunday.
const unavailableDates = { dayOfWeek: [6, 7] };
</script>
<template>
<Field.Root name="checkIn" :class="styles.Field">
<Field.Label :class="styles.Label">Check-in date</Field.Label>
<DateField.Root
locale="en-US"
required
:default-value="defaultValue"
:min="minDate"
:max="maxDate"
:unavailable-dates="unavailableDates"
:class="styles.Root"
>
<DateField.Input :class="styles.Input">
<template #segment="{ segment }">
<DateField.Segment v-if="segment.editable" :segment="segment" :class="styles.Segment" />
<DateField.Literal v-else :segment="segment" :class="styles.Literal" />
</template>
</DateField.Input>
</DateField.Root>
<Field.Description :class="styles.Description">
Choose a weekday in November 2026.
</Field.Description>
<Field.Error :class="styles.Error" />
</Field.Root>
</template>.Field {
display: flex;
flex-direction: column;
align-items: start;
gap: 0.25rem;
}
.Label {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 700;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Root {
display: flex;
align-items: center;
}
.Input {
box-sizing: border-box;
display: flex;
align-items: center;
height: 2rem;
padding: 0 0.5rem;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
font-variant-numeric: tabular-nums;
background-color: white;
color: oklch(14.5% 0 0deg);
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&:focus-within {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Segment {
/* The box follows the text. A browser with no `field-sizing` keeps the width of `size`. */
field-sizing: content;
margin: 0;
padding: 0 0.125rem;
border: 0;
border-radius: 0;
outline: 0;
font: inherit;
text-align: center;
caret-color: transparent;
background-color: transparent;
color: inherit;
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
&::placeholder {
color: oklch(70.8% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(43.9% 0 0deg);
}
}
}
}
.Literal {
color: oklch(43.9% 0 0deg);
white-space: pre;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Value {
margin: 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Description {
margin: 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Error {
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(50.5% 0.213 27.518deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.4% 0.191 22.216deg);
}
}<script setup lang="ts">
import { DateField } from '@vase-ui/vue/date-field';
import { Field } from '@vase-ui/vue/field';
const defaultValue = Temporal.PlainDate.from('2026-12-01');
const minDate = Temporal.PlainDate.from('2026-11-01');
const maxDate = Temporal.PlainDate.from('2026-11-30');
// Saturday and Sunday.
const unavailableDates = { dayOfWeek: [6, 7] };
</script>
<template>
<Field.Root name="checkIn" class="flex flex-col items-start gap-1">
<Field.Label class="text-sm font-bold text-neutral-950 dark:text-white"
>Check-in date</Field.Label
>
<DateField.Root
locale="en-US"
required
:default-value="defaultValue"
:min="minDate"
:max="maxDate"
:unavailable-dates="unavailableDates"
class="flex items-center"
>
<DateField.Input
class="flex h-8 items-center border border-neutral-950 bg-white px-2 text-sm font-normal text-neutral-950 tabular-nums any-pointer-coarse:text-base focus-within:outline-2 focus-within:-outline-offset-1 focus-within:outline-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white dark:focus-within:outline-white"
>
<template #segment="{ segment }">
<DateField.Segment
v-if="segment.editable"
:segment="segment"
class="field-sizing-content px-0.5 text-center caret-transparent outline-0 placeholder:text-neutral-500 focus:bg-neutral-950 focus:text-white focus:placeholder:text-neutral-400 dark:placeholder:text-neutral-400 dark:focus:bg-white dark:focus:text-neutral-950 dark:focus:placeholder:text-neutral-600"
/>
<DateField.Literal
v-else
:segment="segment"
class="whitespace-pre text-neutral-600 dark:text-neutral-400"
/>
</template>
</DateField.Input>
</DateField.Root>
<Field.Description class="text-sm text-neutral-600 dark:text-neutral-400">
Choose a weekday in November 2026.
</Field.Description>
<Field.Error class="text-sm text-red-700 dark:text-red-400" />
</Field.Root>
</template>Clear button
DateField.Clear empties the field and gives the focus to the first segment. Call clear() on the ref of the root to empty the field from your code.
<script setup lang="ts">
import { useId } from 'vue';
import { DateField } from '@vase-ui/vue/date-field';
import styles from './index.module.css';
const id = useId();
const defaultValue = Temporal.PlainDate.from('2026-11-21');
</script>
<template>
<div :class="styles.Field">
<label :for="id" :class="styles.Label">Return date</label>
<DateField.Root :id="id" locale="en-US" :default-value="defaultValue" :class="styles.Root">
<DateField.Input :class="styles.Input">
<template #segment="{ segment }">
<DateField.Segment v-if="segment.editable" :segment="segment" :class="styles.Segment" />
<DateField.Literal v-else :segment="segment" :class="styles.Literal" />
</template>
</DateField.Input>
<DateField.Clear aria-label="Clear the return date" :class="styles.Clear">
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" aria-hidden="true">
<path d="M1 1l8 8M9 1L1 9" stroke="currentColor" stroke-width="1.5" />
</svg>
</DateField.Clear>
</DateField.Root>
</div>
</template>.Field {
display: flex;
flex-direction: column;
align-items: start;
gap: 0.25rem;
}
.Label {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 700;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Root {
display: flex;
align-items: center;
}
.Input {
box-sizing: border-box;
display: flex;
align-items: center;
height: 2rem;
padding: 0 0.5rem;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
font-variant-numeric: tabular-nums;
background-color: white;
color: oklch(14.5% 0 0deg);
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&:focus-within {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Segment {
/* The box follows the text. A browser with no `field-sizing` keeps the width of `size`. */
field-sizing: content;
margin: 0;
padding: 0 0.125rem;
border: 0;
border-radius: 0;
outline: 0;
font: inherit;
text-align: center;
caret-color: transparent;
background-color: transparent;
color: inherit;
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
&::placeholder {
color: oklch(70.8% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(43.9% 0 0deg);
}
}
}
}
.Literal {
color: oklch(43.9% 0 0deg);
white-space: pre;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Value {
margin: 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Clear {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
width: 2rem;
height: 2rem;
margin: 0 0 0 0.25rem;
padding: 0;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
background-color: white;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
&:disabled {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
}<script setup lang="ts">
import { useId } from 'vue';
import { DateField } from '@vase-ui/vue/date-field';
const id = useId();
const defaultValue = Temporal.PlainDate.from('2026-11-21');
</script>
<template>
<div class="flex flex-col items-start gap-1">
<label :for="id" class="text-sm font-bold text-neutral-950 dark:text-white">Return date</label>
<DateField.Root :id="id" locale="en-US" :default-value="defaultValue" class="flex items-center">
<DateField.Input
class="flex h-8 items-center border border-neutral-950 bg-white px-2 text-sm font-normal text-neutral-950 tabular-nums any-pointer-coarse:text-base focus-within:outline-2 focus-within:-outline-offset-1 focus-within:outline-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white dark:focus-within:outline-white"
>
<template #segment="{ segment }">
<DateField.Segment
v-if="segment.editable"
:segment="segment"
class="field-sizing-content px-0.5 text-center caret-transparent outline-0 placeholder:text-neutral-500 focus:bg-neutral-950 focus:text-white focus:placeholder:text-neutral-400 dark:placeholder:text-neutral-400 dark:focus:bg-white dark:focus:text-neutral-950 dark:focus:placeholder:text-neutral-600"
/>
<DateField.Literal
v-else
:segment="segment"
class="whitespace-pre text-neutral-600 dark:text-neutral-400"
/>
</template>
</DateField.Input>
<DateField.Clear
aria-label="Clear the return date"
class="ml-1 flex size-8 items-center justify-center border border-neutral-950 bg-white text-neutral-950 hover:not-disabled:bg-neutral-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:focus-visible:outline-white dark:disabled:border-neutral-400 dark:disabled:text-neutral-400"
>
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" aria-hidden="true">
<path d="M1 1l8 8M9 1L1 9" stroke="currentColor" stroke-width="1.5" />
</svg>
</DateField.Clear>
</DateField.Root>
</div>
</template>Render on the server
Give the field a locale, or a LocaleProvider around it, with the locale of the page. The field does not read the locale of the visitor, so the server HTML and the first render of the browser agree. See Dates and times.
A server and a browser can have other Intl data for one locale. The browser then shows its own layout after the mount. When that layout has another number of parts, Vue can log Hydration completed but contains mismatches one time, and the DOM is correct. An element in the element slot of a part, or a component in as, keeps the attributes of the server.
Keyboard
| Key | Action |
|---|---|
| Tab, Shift+Tab | Moves the focus to the next or the previous segment. Each segment is a stop of the Tab key. |
| Left, Right | Moves the focus to the segment before or after. The keys swap in a right-to-left document. |
| Up, Down | Adds or takes 1, and wraps in the range of the segment. A year does not wrap. An empty segment takes its number from referenceDate, else from today. A day period changes to the other. |
| Page Up, Page Down | Adds or takes 5 for a year, 2 for a month, 7 for a day, 2 for an hour, and 15 for a minute or a second. |
| Home, End | Sets the least or the greatest number of the segment. |
| A digit | Adds the digit, also a digit of the numbering system of the locale. The focus goes to the next segment when the segment is full, or when no digit can make a number. |
| A letter | In a day period segment, selects the period whose text starts with that letter. |
| Backspace, Delete | Empties the segment. Backspace in an empty segment moves the focus to the segment before. |
| Ctrl+V or Cmd+V | Fills the segments from an ISO 8601 text, or from a text in the layout of the locale. |
| Enter | Submits the form, as in a native date input. |
| Other keys with Ctrl, Alt or Cmd | Do their native actions. |
API reference
DateField.Root
Groups the parts of a date field and holds its value.
Renders a <div> element with a hidden form <input> element in it.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
autocomplete | string | undefined | The autocomplete of the form input. | |
calendar | string | undefined | The calendar that the field shows, such as gregory or persian. The default is the calendar
of a value that is not ISO, else the calendar of the locale. A value keeps its own calendar. A
year and month field with no value, defaultValue or referenceDate makes its first value in
this calendar when its months are not ISO months, as in hebrew. | |
defaultValue | Value | null | undefined | The value of a field with no modelValue, at the mount and at a native reset of the form. | |
disabled | boolean | undefined | The user cannot change the value, and the form does not get it. | |
forceLeadingZeros | boolean | undefined | The day, the month and the hour show a leading zero. | |
form | string | undefined | The id of the form of the form input, for a field outside that form. | |
granularity | DateTimeFieldGranularity | undefined | The last unit that the field shows. A date shows day or month, and a year and month shows
month. A date and time shows each unit, with minute as the default. With no value,
defaultValue or referenceDate, it also gives the kind of the first value: day a
Temporal.PlainDate, month a Temporal.PlainYearMonth, and a time unit a
Temporal.PlainDateTime. | |
hideTimeZone | boolean | undefined | The field shows no time zone name for a Temporal.ZonedDateTime. | |
hourCycle | 12 | 24 | undefined | The hour cycle. The default is the hour cycle of the locale. | |
id | string | undefined | The id of the first segment. A <label for> gives it the focus. | |
locale | Intl.LocalesArgument | The locale of the layout, the names and the digits. The default is the locale of the nearest
LocaleProvider, else en-US. | |
max | DateValue | undefined | The latest value. A Temporal.PlainDate limits whole days. A limit with a time limits the time
of a field that shows a time. | |
min | DateValue | undefined | The earliest value. A Temporal.PlainDate limits whole days. A limit with a time limits the
time of a field that shows a time. | |
modelValue | Value | null | undefined | The value: a Temporal.PlainDate, PlainDateTime, ZonedDateTime or PlainYearMonth, or
null for no value. The field gives a value of the same kind, calendar, time and time zone. | |
name | string | undefined | The name of the form input. The name of a Field wins. | |
readonly | boolean | undefined | The user cannot change the value. The form gets the value and does not validate it. | |
referenceDate | DateFieldRootValue | undefined | Gives the kind, the time zone, the calendar and the hidden units of a first value. An arrow key in an empty segment takes its number from this value, else from today. | |
required | boolean | undefined | The user must give a value before a submit. | |
timeZone | string | undefined | The time zone of today, for an arrow key in an empty segment. The default is the zone of a
Temporal.ZonedDateTime value, else the zone of the runtime. | |
unavailableDates | DateMatcher | undefined | The dates that the field refuses: a date, a range, a day of the week, a function or a list. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: DateFieldRootState | The content of the part. |
Events
| Event | Arguments | Description |
|---|---|---|
valueChange | [value: Value | null, details: DateFieldRootChangeEventDetails] | The user changes the value. The value is null while a segment is empty.
details.cancel() keeps each segment as it was. |
update:modelValue | [value: Value | null] | Comes after the change event with the new value, unless a listener cancels the change.
v-model uses it. A reset of the form and clear() emit it with no change event. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
inputElement | HTMLInputElement | null | The input that gives the value to a form. |
clear | () => void | Empties each segment. update:modelValue follows when the field had a value. |
Selectors
| Selector | Description |
|---|---|
[data-empty] | No segment has a number. |
[data-complete] | Each segment has a number, so the field has a value. |
[data-disabled] | The field, its Field or a fieldset around it is disabled. |
[data-readonly] | The field is read-only. |
[data-required] | The field is required. |
[data-valid] | The field is in a Field that is valid. |
[data-invalid] | The field is in a Field that is invalid. |
[data-touched] | The field is in a Field that is touched. |
[data-dirty] | The field is in a Field that is dirty. |
[data-filled] | The field is in a Field that has a value. |
DateField.Input
Holds the segments and the literals of the field.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
segment | segment: DateTimeFieldSegmentindex: number | Renders one item of the layout. The default is DateField.Segment for an editable item and
DateField.Literal for each other item. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DateFieldInputStatesegments: readonly DateTimeFieldSegment[] | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-empty] | No segment has a number. |
[data-complete] | Each segment has a number, so the field has a value. |
[data-disabled] | The field, its Field or a fieldset around it is disabled. |
[data-readonly] | The field is read-only. |
[data-required] | The field is required. |
[data-valid] | The field is in a Field that is valid. |
[data-invalid] | The field is in a Field that is invalid. |
[data-touched] | The field is in a Field that is touched. |
[data-dirty] | The field is in a Field that is dirty. |
[data-filled] | The field is in a Field that has a value. |
DateField.Segment
Edits one unit of the value. Its placeholder is the short name of a date unit, such as mo in
en-US, else --. Its size fits its greatest number and its placeholder. Add
field-sizing: content to its style to make its box follow the text.
Renders an <input> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
segment | { type: EditableSegmentType; editable: true; } | Required | The item that the segment edits. The segment slot of DateField.Input gives it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DateFieldSegmentState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLInputElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-type] | The unit of the segment: year, month, day, hour, minute, second or dayPeriod. |
:placeholder-shown | The segment has no number. |
[data-empty] | No segment has a number. |
[data-complete] | Each segment has a number, so the field has a value. |
:disabled | The field, its Field or a fieldset around it is disabled. |
:read-only | The field is read-only or disabled. |
[aria-required="true"] | The field is required. |
[aria-invalid="true"] | The field is in a Field that is invalid. |
[data-valid] | The field is in a Field that is valid. |
[data-touched] | The field is in a Field that is touched. |
[data-dirty] | The field is in a Field that is dirty. |
[data-filled] | The field is in a Field that has a value. |
DateField.Literal
Shows a separator, an era or the name of a time zone.
Renders a <span> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
segment | { type: "literal" | "era" | "timeZoneName"; editable: false; text: string; } | Required | The item that the part shows. The segment slot of DateField.Input gives it. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DateFieldLiteralState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-type] | The kind of the text: literal for a separator, era or timeZoneName. |
[data-empty] | No segment has a number. |
[data-complete] | Each segment has a number, so the field has a value. |
[data-disabled] | The field, its Field or a fieldset around it is disabled. |
[data-readonly] | The field is read-only. |
[data-required] | The field is required. |
[data-valid] | The field is in a Field that is valid. |
[data-invalid] | The field is in a Field that is invalid. |
[data-touched] | The field is in a Field that is touched. |
[data-dirty] | The field is in a Field that is dirty. |
[data-filled] | The field is in a Field that has a value. |
DateField.Clear
Empties the field and gives the focus to the first segment.
Renders a <button> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | undefined | The user cannot press the button. It is also disabled while the field is empty. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: DateFieldClearState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DateFieldClearState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
:disabled | The button is a native button, and the field is empty, read-only or disabled, or the button has disabled. |
[aria-disabled="true"] | The button is another element, and the field is empty, read-only or disabled, or the button has disabled. |
[data-empty] | No segment has a number. |
[data-complete] | Each segment has a number, so the field has a value. |
[data-readonly] | The field is read-only. |
[data-required] | The field is required. |
[data-valid] | The field is in a Field that is valid. |
[data-invalid] | The field is in a Field that is invalid. |
[data-touched] | The field is in a Field that is touched. |
[data-dirty] | The field is in a Field that is dirty. |
[data-filled] | The field is in a Field that has a value. |
DateField.Root.Granularity
The units that the granularity prop takes.
'month' | 'day' | 'hour' | 'minute' | 'second'
DateField.Root.ChangeEventReason
The reason of valueChange: input-change for typed text, keyboard for a key such as Up or Backspace, and input-clear for deletion by an input method.
'input-change' | 'input-clear' | 'input-paste' | 'keyboard' | 'clear-press'
Differences from Base UI
Base UI has no Date Field. A person types a date into one segment for each part, as the spinbutton pattern describes. The field gives one Temporal value to a form.
- https://www.w3.org/WAI/ARIA/apg/patterns/spinbutton/
- https://html.spec.whatwg.org/multipage/input.html#date-state-(type=date)
- https://www.rfc-editor.org/rfc/rfc9557
Behavior
| Vase UI | Evidence |
|---|---|
A control in a field keeps the id of the developer in the server HTML when no Field.Label of the field renders before it, and a label that renders after the control has that id in for. When a label renders before the control, the control has the generated id of the field until the hydration, because that label names the generated id. Then the control takes its id, and the label follows. In each order, the label names the control in the server HTML. Base UI gives each control in a field the generated id until the hydration, also where no label needs it. |
|
The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.