Skip to content

Time Field ​

A field with one segment for each part of a time, such as the hour and the minute.

vue
<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>
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 { 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 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 TimeField.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: TimeField.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 { 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

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

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

.Fields {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
}
vue
<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 ​

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. An empty segment takes its number from referenceDate, else from midnight. A day period changes to the other.
Page Up, Page DownAdds or takes 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 time input.
Other keys with Ctrl, Alt or CmdDo 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

PropTypeDefaultDescription
autocompletestring | undefinedThe autocomplete of the form input.
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 hour shows a leading zero. A 24-hour cycle always has one.
formstring | undefinedThe id of the form of the form input, for a field outside that form.
granularityTimeFieldRootGranularity | undefined'minute'The last unit that the field shows.
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.
maxTemporal.PlainTime | undefinedThe latest time.
minTemporal.PlainTime | undefinedThe earliest time. A max before min gives a range through midnight.
modelValueValue | null | undefinedThe 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.
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.
referenceDateValue | undefinedGives 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.
requiredboolean | undefinedThe user must give a value before a submit.
stepnumber | undefinedThe step of the time in seconds, from min, else from midnight.
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: TimeFieldRootState
The content of the part.

Events

EventArgumentsDescription
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

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.

TimeField.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 TimeField.Segment for an editable item and TimeField.Literal for each other item.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: TimeFieldInputState
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.

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

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

Slots

SlotSlot propsDescription
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: TimeFieldSegmentState
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: 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.

TimeField.Literal ​

Shows a separator 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 TimeField.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: TimeFieldLiteralState
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, 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

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: TimeFieldClearState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: TimeFieldClearState
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.

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.

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.