Fragiola

API: components

TimeField

A time of day typed in segments, each an APG spinbutton, with the locale's hour cycle and day period, forms and Field support, in each framework.

A time of day typed in parts: the hour, the minutes (and seconds) and, on a 12-hour clock, the day period. It is the DateField's anatomy over a time: its Input and Segment are DateField's, named time-field-* inside a TimeField. It works in a native <form> and in a Field. Each segment is an APG spinbutton.

Meeting time
Gallery

Behaviour

  • The locale's clock: a 12- or 24-hour cycle from the locale (hourCycle overrides it), the day period's text and the segments' names from Intl.
  • Value: a PlainTime ({ hour, minute, second, millisecond }, hour 0–23), set once every segment is; null until then.
  • The day period: typed by the first letter of its AM or PM text in the locale; the arrows toggle it. A 12-hour hour steps within its half of the day (11 AM + 1 is 12 AM).
  • Validation: a time before min or after max is invalid; a min later than max is no range across midnight, and stepping across midnight never makes a time valid.
  • Forms: a hidden native time input submits the ISO time (14:30, 14:30:05 at second), with min and max.

Anatomy

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

Usage

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

<TimeField.Root value={time} onValueChange={setTime} min={opens} max={closes} name="meeting">
    <TimeField.Input aria-label="Meeting time" />
</TimeField.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 and the Segment are DateField's.

Root

proptypedefaultdescription
valuePlainTime | nullthe value, controlled
defaultValuePlainTime | nullnullthe initial value, uncontrolled
onValueChange(value, details: { reason, event }) => voidevery change of the value
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
requiredbooleanfalsethe hidden input is required
readOnlybooleanfalsefocusable and submitted, but nothing changes it
disabledbooleanfalseno segment is focusable, nothing is submitted
namestringthe hidden input's name (a Field's wins)

Input

Its children: a function of each segment (Vue: the default slot's { segment }; Angular: @for over segments()); with none, every segment with its own text.

Segment

proptypedefaultdescription
segmentDateSegmentrequiredone of the Input's segments

State and part attributes

As DateField's, named time-field-*. The day period's segment has inputmode="text" and aria-valuetext its AM or PM text.

Keyboard

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

Exports

entryexports
@fragiola/primitives-react/time-fieldChangeDetails, ChangeReason, DateFieldInputProps, DateFieldRootSharedProps, DateFieldSegmentProps, DateFieldSegmentState, DateFieldState, DateSegment, PlainTime, RenderProp, SegmentGranularity, SegmentType, TimeField, TimeFieldRootProps
@fragiola/primitives-vue/time-fieldChangeDetails, ChangeReason, DateFieldInputSlots, DateFieldRootSharedProps, DateFieldSegmentProps, DateFieldSegmentState, DateFieldState, DateSegment, PlainTime, RenderSlotProps, SegmentGranularity, SegmentType, TimeField, TimeFieldRootEmits, TimeFieldRootProps
@fragiola/primitives-angular/time-fieldChangeDetails, ChangeReason, DateFieldInput, DateFieldSegment, DateFieldSegmentState, DateFieldState, DateSegment, PlainTime, SegmentGranularity, SegmentType, TimeFieldRoot, ValueChangeEvent