Time Range Field
NewA field for a start time and an end time.
Preview
Installation
npx sigma-ui@latest add time-range-fieldUsage
<script setup lang="ts">
import { type Ref, ref } from 'vue';
import { Time } from '@internationalized/date';
import type { TimeValue } from 'reka-ui';
import { TimeRangeField } from '@/components/ui/time-range-field';
const value = ref({
start: new Time(9, 0),
end: new Time(17, 0),
}) as Ref<{ start: TimeValue; end: TimeValue }>;
</script>
<template>
<TimeRangeField v-model="value" />
</template>v-modelis a{ start, end }pair of @internationalized/dateTimevalues.granularityisminuteby default, andhourCycleswitches between a 12-hour and a 24-hour clock.- The field renders the start segments, a dash, and the end segments, each in a
TimeRangeFieldInput. To render them yourself, use the default slot. It givessegments.startandsegments.end, and each segment has apartand thevalueto show:
<template>
<TimeRangeField v-slot="{ segments }" v-model="value">
<TimeRangeFieldInput
v-for="(item, index) in segments.start"
:key="`start-${item.part}-${index}`"
:part="item.part"
type="start"
>
{{ item.value }}
</TimeRangeFieldInput>
<span>to</span>
<TimeRangeFieldInput
v-for="(item, index) in segments.end"
:key="`end-${item.part}-${index}`"
:part="item.part"
type="end"
>
{{ item.value }}
</TimeRangeFieldInput>
</TimeRangeField>
</template>Related
- Time Field, for a single time
Examples
Office hours
API Reference
TimeRangeField
Props
| Prop | Type | Default |
|---|---|---|
defaultValueThe default value for the field | TimeRange | - |
defaultPlaceholderThe default placeholder time | TimeValue | - |
placeholderThe placeholder time, 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 | TimeRange | null | - |
hourCycleThe hour cycle used for formatting times. Defaults to the local preference | HourCycle | - |
stepThe stepping interval for the time fields. Defaults to | DateStep | - |
granularityThe granularity to use for formatting times. Defaults to minute. The field will render segments for each part of the time 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 time that can be selected | TimeValue | - |
minValueThe minimum time that can be selected | TimeValue | - |
localeThe locale to use for formatting times | 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 | - |
isTimeUnavailableA function that returns whether or not a time is unavailable | Matcher | - |
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: TimeRange] |
update:placeholderEvent handler called whenever the placeholder value changes | [date: TimeValue] |
Slots
| Slot | Scope |
|---|---|
defaultThe start and end segments. Each one renders in a | { modelValue: TimeRange | null; segments: { start: { part: SegmentPart; value: string; }[]; end: { part: SegmentPart; value: string; }[]; }; isInvalid: boolean; } |
TimeRangeFieldInput
Props
| Prop | Type | Default |
|---|---|---|
partrequiredThe part of the date to render | SegmentPart | - |
typerequiredThe type of field to render (start or end) | DateRangeType | - |
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
Each segment is a spin button. Arrow keys change the focused segment, and left and right move between segments.
| Key | Description |
|---|---|
| ArrowUp or ArrowDown | Increases or decreases the focused segment. |
| ArrowLeft or ArrowRight | Moves to the previous or next segment. |