Time Field
NewA field for typing a time, one segment at a time.
Preview
Installation
npx sigma-ui@latest add time-fieldUsage
<script setup lang="ts">
import { ref } from 'vue';
import { type TimeValue } from 'reka-ui';
import { TimeField } from '@/components/ui/time-field';
const value = ref<TimeValue>();
</script>
<template>
<TimeField v-model="value" />
</template>v-modelis aTimefrom @internationalized/date. ACalendarDateTimeorZonedDateTimeworks too, and only its time is edited.granularitypicks the smallest segment (minuteby default, orhour,second), andhourCycleswitches between a 12-hour and a 24-hour clock.minValueandmaxValuelimit the range. A value outside it setsdata-invalidon the field, and the field shows the destructive border.- The field renders each segment in a
TimeFieldInput. Pass your own default slot to render the segments yourself, for example to add an icon. - Give the field an
idand point a label at it withfor. Clicking the label focuses the first segment.
Related
- Date Field
- Time Range Field, for a start and an end time
Examples
With label
Granularity and hour cycle
Min and max
Disabled
Invalid
Form
API Reference
TimeField
Props
| Prop | Type | Default |
|---|---|---|
defaultValueThe default value for the calendar | TimeValue | - |
defaultPlaceholderThe default placeholder date | TimeValue | - |
placeholderThe placeholder date, which is used to determine what time to display when no time is selected. This updates as the user navigates the field | TimeValue | - |
modelValueThe controlled checked state of the field. Can be bound as | TimeValue | null | - |
hourCycleThe hour cycle used for formatting times. Defaults to the local preference | HourCycle | - |
stepThe stepping interval for the time fields. Defaults to | DateStep | - |
stepSnappingWhether to enforce snapping the value to the nearest step increment after input. Defaults to | boolean | - |
granularityThe granularity to use for formatting times. Defaults to minute if a Time is provided, otherwise defaults to minute. The field will render segments for each part of the date up to and including the specified granularity | "hour" | "minute" | "second" | - |
hideTimeZoneWhether or not to hide the time zone segment of the field | boolean | - |
maxValueThe maximum date that can be selected | TimeValue | - |
minValueThe minimum date that can be selected | TimeValue | - |
localeThe locale to use for formatting dates | string | - |
disabledWhether or not the time field is disabled | boolean | - |
readonlyWhether or not the time field is readonly | boolean | - |
idId of the element | string | - |
dirThe reading direction of the time field when applicable. <br> If omitted, inherits globally from | Direction | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
nameThe name of the field. Submitted with its owning form as part of a name/value pair. | string | - |
requiredWhen | boolean | - |
Events
| Event | Payload |
|---|---|
update:modelValueEvent handler called whenever the model value changes | [date: TimeValue] |
update:placeholderEvent handler called whenever the placeholder value changes | [date: TimeValue] |
Slots
| Slot | Scope |
|---|---|
defaultThe time segments. Each one renders in a | { modelValue: TimeValue | null; segments: { part: SegmentPart; value: string; }[]; isInvalid: boolean; } |
TimeFieldInput
Props
| Prop | Type | Default |
|---|---|---|
partrequiredThe part of the date to render | SegmentPart | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
Accessibility
The field is a group of spin buttons, one for each segment (hour, minute, and day period). Typing a number fills the focused segment and moves to the next one.
| Key | Description |
|---|---|
| ArrowUp or ArrowDown | Increases or decreases the focused segment. |
| ArrowLeft or ArrowRight | Moves to the previous or next segment. |
| Backspace | Deletes the last digit of the focused segment. |
| Tab | Moves to the next segment, then out of the field. |