Fragiola

API: components

TimeRangeField

A start and an end time of day typed in segments as one control, no range across midnight, two form values and Field support, in each framework.

A start time and an end time of day typed in parts, opening hours or a meeting's slot: the DateRangeField's anatomy over two times. Its Input is DateRangeField's and its Segment DateField's, named time-range-field-* inside a TimeRangeField. Each segment is an APG spinbutton.

Behaviour

  • Value: a TimeRange ({ start, end } of PlainTimes), set once every segment of both ends is; null until then.
  • One sequence: typing moves on from the start into the end, Backspace and the arrows cross back, as a DateRangeField's.
  • No range across midnight: an end before the start is invalid, as TimeField's reversed min / max; a time before min or after max too.
  • Forms: two hidden native time inputs, startName and endName, with crossed bounds.

Anatomy

partelementdata-primitives-partrole
Rootdivtime-range-field-rootholds the value; renders the hidden inputs after it
Inputdivtime-range-field-inputgroup of one end's segments (range)
Segmentspantime-range-field-segmentspinbutton, or a literal hidden from assistive technology
(hidden inputs)input type="time" ×2time-range-field-hidden-inputwhat the form submits

Usage

import { TimeRangeField } from "@fragiola/primitives-react/time-range-field";

<TimeRangeField.Root value={hours} onValueChange={setHours} startName="opens" endName="closes">
    <TimeRangeField.Input range="start" aria-label="Opens" />
    <span aria-hidden="true">–</span>
    <TimeRangeField.Input range="end" aria-label="Closes" />
</TimeRangeField.Root>;

Props

Every part also takes what the primitive contract gives. Vue binds the value as v-model:value with @value-change; Angular as [(value)] with (valueChangeDetails). The Input is DateRangeField's, the Segment DateField's.

Root

proptypedefaultdescription
valueTimeRange | nullthe range, controlled
defaultValueTimeRange | nullnullthe initial range, uncontrolled
onValueChange(value, details: { reason, event }) => voidevery change of the range
granularity"hour" | "minute" | "second""minute"the smallest segment
placeholderValuePlainTimemidnightwhat an arrow on an empty segment starts from
hourCycle12 | 24the locale'sthe clock
minPlainTimetimes before it are invalid
maxPlainTimetimes after it are invalid
localestringthe document's langthe segments' order, digits and names
requiredbooleanfalseboth hidden inputs are required
readOnlybooleanfalsefocusable and submitted, but nothing changes it
disabledbooleanfalseno segment is focusable, nothing is submitted
startNamestringthe start's hidden input name
endNamestringthe end's hidden input name

Input

proptypedefaultdescription
range"start" | "end"requiredthe end whose segments it holds

Segment

proptypedefaultdescription
segmentDateSegmentrequiredone of the Input's segments

State and part attributes

As DateRangeField's, named time-range-field-*.

Keyboard

As DateRangeField's; on a day period, a letter sets it and the arrows toggle it.

Exports

entryexports
@fragiola/primitives-react/time-range-fieldChangeDetails, ChangeReason, DateFieldInputProps, DateFieldSegmentProps, DateFieldSegmentState, DateFieldState, DateRangeFieldInputProps, DateRangeFieldRootSharedProps, DateSegment, PlainTime, RangeEnd, RenderProp, SegmentGranularity, SegmentType, TimeRange, TimeRangeField, TimeRangeFieldRootProps
@fragiola/primitives-vue/time-range-fieldChangeDetails, ChangeReason, DateFieldInputSlots, DateFieldSegmentProps, DateFieldSegmentState, DateFieldState, DateRangeFieldInputProps, DateRangeFieldRootSharedProps, DateSegment, PlainTime, RangeEnd, RenderSlotProps, SegmentGranularity, SegmentType, TimeRange, TimeRangeField, TimeRangeFieldRootEmits, TimeRangeFieldRootProps
@fragiola/primitives-angular/time-range-fieldChangeDetails, ChangeReason, DateFieldSegment, DateFieldSegmentState, DateFieldState, DateRangeFieldInput, DateSegment, PlainTime, RangeEnd, SegmentGranularity, SegmentType, TimeRange, TimeRangeFieldRoot, ValueChangeEvent