Skip to content
Focsd homeFocsd homeFocsd
Forms

Time field

Hours and minutes as keyboard-friendly segments.

  • Tag: focsd-time-field
  • Pattern: Spinbutton segments
  • Category: Forms

Example

HTML
<div class="stack">
<focsd-time-field
label="Meeting time"
value="09:30"
hour-cycle="h23"
step="5"></focsd-time-field>
<focsd-time-field label="Alarm" value="13:05" hour-cycle="h12"></focsd-time-field>
</div>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-time-field.js';
</script>
<focsd-time-field label="Meeting time" value="09:30" hour-cycle="h23" step="5"></focsd-time-field>

API

Attributes

AttributePropertyTypeDefault
namenamestring—
disableddisabledbooleanfalse
requiredrequiredbooleanfalse
readonlyreadOnlybooleanfalse
aria-labelhostAriaLabelstring | nullnull
aria-descriptionhostAriaDescriptionstring | nullnull
aria-labelledbyhostAriaLabelledBystring | nullnull
aria-describedbyhostAriaDescribedBystring | nullnull
label-positionlabelPosition'top' | 'start' | 'end' | undefined—
hinthintstring—
errorerror——
warningwarningstring | undefined—
successsuccessstring | undefined—
error-messageerrorMessagestring | undefined—
warning-messagewarningMessagestring | undefined—
warning-patternwarningPatternstring | undefined—
labellabelstring—
valuevaluestring—
hour-cyclehourCycle'' | 'h12' | 'h23'—
stepstepnumber1
minminstring—
maxmaxstring—
localelocalestring—

Methods

MethodDescription
describedByIds()IDs to add to the inner control's aria-describedby: the hint, then the shown message.
checkValidity()True when the value is valid; otherwise fires invalid and returns false, like native.
reportValidity()Like checkValidity(), and also shows the browser's validation message when invalid.
setCustomValidity(message)Set (non-empty) or clear (empty string) a custom validation error, like native controls.
setValidityState(flags, message, anchor)For subclasses: set the validity flags and message. anchor is the element the browser points its message at.
validate()Show (or clear) the error from the control's own checks: required, type, pattern, min, max and the like. Uses error-message, else the browser's localized message. An error the author set (a server error, say) is left as it is.
clearValidation()Clear the error and warning that validate() and warning-pattern showed (a form reset does).
emitValue(commit)For subclasses: fire the value events, as a native control does on a user edit: input (bubbles, composed), then with commit also change (bubbles, stays in its tree).
idrefText(ids)For subclasses: the text of the elements an ID reference list names, resolved in the host's tree (ID references cannot cross a shadow root), joined by spaces.
stepUp(n)Move by n steps of step minutes, clamped to min/max. Fires no events, like native.
stepDown(n)Move back by n steps of step minutes, clamped to min/max. Fires no events, like native.

Events

EventDescription
inputFired on every user edit of the value.
changeFired when the user commits a change to the value or state.

CSS parts

Style the inside of the component with ::part(), for example focsd-time-field::part(divider).

PartDescription
dividerThe ":" between hours and minutes.
fieldThe field element.
labelThe label element.
layoutThe wrapper that places the label beside or above the body.
bodyThe field, hint and message.
hintThe author's hint.
messageThe shown error, warning or success message (also `error`, `warning` or `success`).
message-iconThe message's icon.
announcerThe visually hidden status region.
segmentEach hour, minute or AM/PM segment.

Accessibility

  • min, max, valueAsDate, valueAsNumber, stepUp() and stepDown() work as on a native time input; step is in minutes. Not supported: autocomplete (the segments are not native inputs). Use a native <input type="time"> where autofill matters.
  • A labeled role="group" of role="spinbutton" segments named "Hours", "Minutes" (and "AM/PM" in 12-hour mode), each with aria-valuetext.
  • Segments stay in hours-then-minutes order in every script direction.
  • The form value is always 24-hour HH:MM.
  • Form-associated: participates in FormData, validation, reset, fieldset disabled and back/forward restore.

Keyboard

KeyAction
Arrow Up / DownChange the segment
DigitsType a value; moves on when complete
Arrow Left / RightPrevious / next segment
A / P (AM/PM segment)Set AM / PM
Backspace / DeleteClear the segment