Time Field
A field with one segment for each part of a time, such as the hour and the minute.
<script setup lang="ts">
import { useId } from 'vue';
import { TimeField } from '@vase-ui/vue/time-field';
import styles from './index.module.css';
const id = useId();
</script>
<template>
<div :class="styles.Field">
<label :for="id" :class="styles.Label">Alarm</label>
<TimeField.Root :id="id" locale="en-US" :class="styles.Root">
<TimeField.Input :class="styles.Input">
<template #segment="{ segment }">
<TimeField.Segment v-if="segment.editable" :segment="segment" :class="styles.Segment" />
<TimeField.Literal v-else :segment="segment" :class="styles.Literal" />
</template>
</TimeField.Input>
</TimeField.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 { TimeField } from '@vase-ui/vue/time-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">Alarm</label>
<TimeField.Root :id="id" locale="en-US" class="flex items-center">
<TimeField.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 }">
<TimeField.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"
/>
<TimeField.Literal
v-else
:segment="segment"
class="whitespace-pre text-neutral-600 dark:text-neutral-400"
/>
</template>
</TimeField.Input>
</TimeField.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, giveTimeField.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:
TimeField.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 { TimeField } from '@vase-ui/vue/time-field';
</script>
<template>
<TimeField.Root>
<TimeField.Input>
<template #segment="{ segment }">
<TimeField.Segment v-if="segment.editable" :segment="segment" />
<TimeField.Literal v-else :segment="segment" />
</template>
</TimeField.Input>
<TimeField.Clear aria-label="Clear the time">×</TimeField.Clear>
</TimeField.Root>
</template>Examples
Seconds
Set granularity to second to add the seconds.
Value: 07:30:00
<script setup lang="ts">
import { shallowRef, useId } from 'vue';
import { TimeField } from '@vase-ui/vue/time-field';
import styles from './index.module.css';
const id = useId();
const value = shallowRef<Temporal.PlainTime | null>(Temporal.PlainTime.from('07:30:00'));
</script>
<template>
<div :class="styles.Field">
<label :for="id" :class="styles.Label">Lap time</label>
<TimeField.Root
:id="id"
v-model="value"
granularity="second"
locale="en-US"
:class="styles.Root"
>
<TimeField.Input :class="styles.Input">
<template #segment="{ segment }">
<TimeField.Segment v-if="segment.editable" :segment="segment" :class="styles.Segment" />
<TimeField.Literal v-else :segment="segment" :class="styles.Literal" />
</template>
</TimeField.Input>
</TimeField.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 { TimeField } from '@vase-ui/vue/time-field';
const id = useId();
const value = shallowRef<Temporal.PlainTime | null>(Temporal.PlainTime.from('07:30:00'));
</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">Lap time</label>
<TimeField.Root
:id="id"
v-model="value"
granularity="second"
locale="en-US"
class="flex items-center"
>
<TimeField.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 }">
<TimeField.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"
/>
<TimeField.Literal
v-else
:segment="segment"
class="whitespace-pre text-neutral-600 dark:text-neutral-400"
/>
</template>
</TimeField.Input>
</TimeField.Root>
<p class="text-sm text-neutral-600 dark:text-neutral-400">
Value: {{ value?.toString() ?? 'none' }}
</p>
</div>
</template>Hour cycle
A 12-hour cycle adds a day period segment. The locale sets where the segment goes: after the minute in en-US, and before the hour in ko-KR. A 24-hour cycle has no day period.
<script setup lang="ts">
import { useId } from 'vue';
import { TimeField } from '@vase-ui/vue/time-field';
import styles from './index.module.css';
const twelveId = useId();
const twentyFourId = useId();
const defaultValue = Temporal.PlainTime.from('15:04');
</script>
<template>
<div :class="styles.Fields">
<div :class="styles.Field">
<label :for="twelveId" :class="styles.Label">12-hour cycle</label>
<TimeField.Root
:id="twelveId"
:default-value="defaultValue"
:hour-cycle="12"
locale="en-US"
:class="styles.Root"
>
<TimeField.Input :class="styles.Input">
<template #segment="{ segment }">
<TimeField.Segment v-if="segment.editable" :segment="segment" :class="styles.Segment" />
<TimeField.Literal v-else :segment="segment" :class="styles.Literal" />
</template>
</TimeField.Input>
</TimeField.Root>
</div>
<div :class="styles.Field">
<label :for="twentyFourId" :class="styles.Label">24-hour cycle</label>
<TimeField.Root
:id="twentyFourId"
:default-value="defaultValue"
:hour-cycle="24"
locale="en-US"
:class="styles.Root"
>
<TimeField.Input :class="styles.Input">
<template #segment="{ segment }">
<TimeField.Segment v-if="segment.editable" :segment="segment" :class="styles.Segment" />
<TimeField.Literal v-else :segment="segment" :class="styles.Literal" />
</template>
</TimeField.Input>
</TimeField.Root>
</div>
</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);
}
}
.Fields {
display: flex;
flex-wrap: wrap;
gap: 1.5rem;
}<script setup lang="ts">
import { useId } from 'vue';
import { TimeField } from '@vase-ui/vue/time-field';
const twelveId = useId();
const twentyFourId = useId();
const defaultValue = Temporal.PlainTime.from('15:04');
</script>
<template>
<div class="flex flex-wrap gap-6">
<div class="flex flex-col items-start gap-1">
<label :for="twelveId" class="text-sm font-bold text-neutral-950 dark:text-white"
>12-hour cycle</label
>
<TimeField.Root
:id="twelveId"
:default-value="defaultValue"
:hour-cycle="12"
locale="en-US"
class="flex items-center"
>
<TimeField.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 }">
<TimeField.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"
/>
<TimeField.Literal
v-else
:segment="segment"
class="whitespace-pre text-neutral-600 dark:text-neutral-400"
/>
</template>
</TimeField.Input>
</TimeField.Root>
</div>
<div class="flex flex-col items-start gap-1">
<label :for="twentyFourId" class="text-sm font-bold text-neutral-950 dark:text-white"
>24-hour cycle</label
>
<TimeField.Root
:id="twentyFourId"
:default-value="defaultValue"
:hour-cycle="24"
locale="en-US"
class="flex items-center"
>
<TimeField.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 }">
<TimeField.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"
/>
<TimeField.Literal
v-else
:segment="segment"
class="whitespace-pre text-neutral-600 dark:text-neutral-400"
/>
</template>
</TimeField.Input>
</TimeField.Root>
</div>
</div>
</template>Limits and steps
Give min and max to limit the time, and step to set the step of the time in seconds. A max before min gives a range through midnight. An earlier time gives rangeUnderflow, and a later time gives rangeOverflow. A time that is not a multiple of the step from min, or from midnight with no min, gives stepMismatch. Some empty segments give badInput, as in a native time input.
Put the field in a Field to show these errors with Field.Error and its match. The browser finds the limits and the step of a Temporal.PlainTime, because its form input has the type time. The field finds each other failure itself, and sets it as a custom error of the form input with the message of the browser. Field.Error reads it as a native failure. Outside a Field, inputElement.validity.customError is then true, and validationMessage says which failure it is.
Clear button
TimeField.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.
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, such as another hour cycle. 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. An empty segment takes its number from referenceDate, else from midnight. A day period changes to the other. |
| Page Up, Page Down | Adds or takes 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 time input. |
| Other keys with Ctrl, Alt or Cmd | Do their native actions. |
API reference
TimeField.Root
Groups the parts of a time 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. | |
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 hour shows a leading zero. A 24-hour cycle always has one. | |
form | string | undefined | The id of the form of the form input, for a field outside that form. | |
granularity | TimeFieldRootGranularity | undefined | 'minute' | The last unit that the field shows. |
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 | Temporal.PlainTime | undefined | The latest time. | |
min | Temporal.PlainTime | undefined | The earliest time. A max before min gives a range through midnight. | |
modelValue | Value | null | undefined | The value: a Temporal.PlainTime, PlainDateTime or ZonedDateTime, or null for no value.
The field gives a value of the same kind, with the date and the time zone of the value. | |
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 | Value | undefined | Gives the kind, the date and the time zone of a first value. With no referenceDate and no
defaultValue, the first value is a Temporal.PlainTime. An arrow key in an empty segment
takes its number from this value, else from midnight. | |
required | boolean | undefined | The user must give a value before a submit. | |
step | number | undefined | The step of the time in seconds, from min, else from midnight. | |
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: TimeFieldRootState | The content of the part. |
Events
| Event | Arguments | Description |
|---|---|---|
valueChange | [value: Value | null, details: TimeFieldRootChangeEventDetails] | 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. |
TimeField.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 TimeField.Segment for an editable item and
TimeField.Literal for each other item. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: TimeFieldInputStatesegments: 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. |
TimeField.Segment
Edits one unit of the value. Its placeholder is --. 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 TimeField.Input gives it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: TimeFieldSegmentState | 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: 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. |
TimeField.Literal
Shows a separator 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 TimeField.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: TimeFieldLiteralState | 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, 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. |
TimeField.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: TimeFieldClearState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: TimeFieldClearState | 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. |
TimeField.Root.Granularity
The units that the granularity prop takes.
'hour' | 'minute' | 'second'
TimeField.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 Time Field. A person types a time 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#time-state-(type=time)
- 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.