Skip to content

Date Field ​

A field with one segment for each part of a date, such as the month, the day and the year.

vue
<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>
css
.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);
  }
}
vue
<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 a Temporal polyfill for an engine that has none, such as Safari and Node.js 24. Use TypeScript 6.0, or set skipLibCheck. See Dates and times.
  • Form controls must have an accessible name: Put the field in a Field with a Field.Label, give DateField.Root an aria-label or an aria-labelledby, or point a <label for> at the id of 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.Clear has no content and no name of its own. Give it content and an aria-label in the language of the page.

Anatomy ​

Import the component and assemble its parts:

vue
<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

vue
<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>
css
.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);
  }
}
vue
<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.

GMT+9

Value: 2026-11-14T15:04:00+09:00[Asia/Tokyo]

vue
<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>
css
.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);
  }
}
vue
<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

vue
<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>
css
.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);
  }
}
vue
<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:

ValueForm inputForm textChecks
Temporal.PlainDatedate2026-11-14Native
Temporal.PlainDateTimedatetime-local2026-11-14T15:04Native
Temporal.ZonedDateTimetext2026-11-14T15:04+09:00[Asia/Tokyo]required native, the limits by the field
Temporal.PlainYearMonthtext2026-11required 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.
  • rangeUnderflow and rangeOverflow: a limit, for each kind of value.
  • customError: a date that unavailableDates matches. 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.

vue
<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>
css
.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);
  }
}
vue
<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.

vue
<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>
css
.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);
    }
  }
}
vue
<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 ​

KeyAction
Tab, Shift+TabMoves the focus to the next or the previous segment. Each segment is a stop of the Tab key.
Left, RightMoves the focus to the segment before or after. The keys swap in a right-to-left document.
Up, DownAdds 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 DownAdds 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, EndSets the least or the greatest number of the segment.
A digitAdds 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 letterIn a day period segment, selects the period whose text starts with that letter.
Backspace, DeleteEmpties the segment. Backspace in an empty segment moves the focus to the segment before.
Ctrl+V or Cmd+VFills the segments from an ISO 8601 text, or from a text in the layout of the locale.
EnterSubmits the form, as in a native date input.
Other keys with Ctrl, Alt or CmdDo 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

PropTypeDefaultDescription
autocompletestring | undefinedThe autocomplete of the form input.
calendarstring | undefinedThe 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.
defaultValueValue | null | undefinedThe value of a field with no modelValue, at the mount and at a native reset of the form.
disabledboolean | undefinedThe user cannot change the value, and the form does not get it.
forceLeadingZerosboolean | undefinedThe day, the month and the hour show a leading zero.
formstring | undefinedThe id of the form of the form input, for a field outside that form.
granularityDateTimeFieldGranularity | undefinedThe 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.
hideTimeZoneboolean | undefinedThe field shows no time zone name for a Temporal.ZonedDateTime.
hourCycle12 | 24 | undefinedThe hour cycle. The default is the hour cycle of the locale.
idstring | undefinedThe id of the first segment. A <label for> gives it the focus.
localeIntl.LocalesArgumentThe locale of the layout, the names and the digits. The default is the locale of the nearest LocaleProvider, else en-US.
maxDateValue | undefinedThe latest value. A Temporal.PlainDate limits whole days. A limit with a time limits the time of a field that shows a time.
minDateValue | undefinedThe earliest value. A Temporal.PlainDate limits whole days. A limit with a time limits the time of a field that shows a time.
modelValueValue | null | undefinedThe 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.
namestring | undefinedThe name of the form input. The name of a Field wins.
readonlyboolean | undefinedThe user cannot change the value. The form gets the value and does not validate it.
referenceDateDateFieldRootValue | undefinedGives 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.
requiredboolean | undefinedThe user must give a value before a submit.
timeZonestring | undefinedThe 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.
unavailableDatesDateMatcher | undefinedThe dates that the field refuses: a date, a range, a day of the week, a function or a list.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA 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

SlotSlot propsDescription
default
state: DateFieldRootState
The content of the part.

Events

EventArgumentsDescription
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

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.
inputElementHTMLInputElement | nullThe input that gives the value to a form.
clear() => voidEmpties each segment. update:modelValue follows when the field had a value.

Selectors

SelectorDescription
[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

PropTypeDefaultDescription
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA 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

SlotSlot propsDescription
segment
segment: DateTimeFieldSegment
index: 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) => void
state: DateFieldInputState
segments: readonly DateTimeFieldSegment[]
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[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

PropTypeDefaultDescription
segment{ type: EditableSegmentType; editable: true; }RequiredThe item that the segment edits. The segment slot of DateField.Input gives it.

Slots

SlotSlot propsDescription
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: DateFieldSegmentState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLInputElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-type]The unit of the segment: year, month, day, hour, minute, second or dayPeriod.
:placeholder-shownThe segment has no number.
[data-empty]No segment has a number.
[data-complete]Each segment has a number, so the field has a value.
:disabledThe field, its Field or a fieldset around it is disabled.
:read-onlyThe 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

PropTypeDefaultDescription
segment{ type: "literal" | "era" | "timeZoneName"; editable: false; text: string; }RequiredThe item that the part shows. The segment slot of DateField.Input gives it.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA 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

SlotSlot propsDescription
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: DateFieldLiteralState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[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

PropTypeDefaultDescription
disabledboolean | undefinedThe user cannot press the button. It is also disabled while the field is empty.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA 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

SlotSlot propsDescription
default
state: DateFieldClearState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: DateFieldClearState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
:disabledThe 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.

Behavior ​

Vase UIEvidence
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.