TimeRangeField

Data input

A span of time typed as two times, segment by segment: <TimeRangeField.Root> (bind:value a { start, end } of Times, granularity, hourCycle) holds a TimeRangeField.Label (which names it; use it instead of Field.Label) and TimeRangeField.Inputs, one box that draws the start and end TimeRangeField.Inputs. Inside a Field, its description and error describe the inputs.

import { TimeRangeField } from '@limerdev/zest';
TimeRangeField for AI tools (llms.txt)
Use for
Opening hours, a shift, a meeting slot.
Don't
A period of days: use DateRangeField. A single time: use TimeField.

Examples

Basic

A shift, from and to, in 24 hours.

Shift

Props

Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that renders your own element, with props to spread on it).

TimeRangeField.Root

Prop Type Default Description
disabled boolean false If true, the time field will be disabled and users will not be able to interact with it. This also disables the hidden input element if the time field is used in a form.
errorMessageId string – The id of the element which contains the error messages for the time field when the time is invalid.
granularity "hour" | "minute" | "second" 'minute' The granularity of the time field. This determines which segments will be includes in the segments array used to build the time field. Granularity is only used for visual purposes, and does not impact the value of the time field. You can have the same value synced between multiple time fields with different granularities and they will all contain the same value.
hideTimeZone boolean false; Whether or not to hide the timeZoneName segment from the time field.
hourCycle 12 | 24 - the locale's default time format The format to use for displaying the time in the input. If using a 12 hour clock, ensure you also include the dayPeriod segment in your input to ensure the user can select AM/PM.
locale string 'en' The locale to use for formatting the time field.
maxValue TimeValue – The maximum acceptable date. When provided, the time field will be marked as invalid if the user enters a date after this date.
minValue TimeValue – The minimum acceptable date. When provided, the time field will be marked as invalid if the user enters a date before this date.
onEndValueChange OnChangeFn<Time | undefined> – A callback function called when the end value changes. This doesn't necessarily mean the value has updated and should be used to apply cosmetic changes to the field when only part of the value is changed/completed.
onInvalid TimeOnInvalid – A callback fired when the time field's value is invalid. Use this to display an error message to the user.
onPlaceholderChange OnChangeFn<TimeValue | undefined> – A callback that is called when the time field's placeholder value changes.
onStartValueChange OnChangeFn<Time | undefined> – A callback function called when the start value changes. This doesn't necessarily mean the value has updated and should be used to apply cosmetic changes to the field when only part of the value is changed/completed.
onValueChange OnChangeFn<TimeRange<Time> | undefined> – A callback that is called when the value of the date range field changes.
placeholder bindable TimeValue – The placeholder value of the time field. This determines the format and what date the field starts at when it is empty.
readonly boolean false If true, the time field will be readonly, and users will not be able to edit the values of any of the individual segments.
readonlySegments ("hour" | "minute" | "second" | "dayPeriod")[] – An array of segment names that should be readonly. If provided, only the segments not in this array will be editable.
required boolean false If true, the time field will be required, which is useful when used within a form. If the time field is empty when the form is submitted, the form will not be valid.
validate TimeRangeValidator<Time> – A function that returns a string or array of strings as validation errors if the date is invalid, or nothing if the date is valid
value bindable TimeRange<Time> – The value of the date range field.

TimeRangeField.Label

No props of its own beyond the common ones.

TimeRangeField.Inputs

No props of its own beyond the common ones.

TimeRangeField.Input

Prop Type Default Description
name string – The name to use for the hidden input element associated with this input used for form submission.
type required "start" | "end" – Whether this input represents the start or end of the date range.

TimeRangeField.Segment

Prop Type Default Description
part required "hour" | "minute" | "second" | "dayPeriod" | "timeZoneName" | "literal" –