Time field
Hours and minutes as keyboard-friendly segments.
Example
<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>import { TimeField } from '@focsd-dev/react';
export function Example() { return <TimeField onChange={(e) => console.log(e.target)} label="Meeting time" value="09:30" hour-cycle="h23" step="5"></TimeField>;}<script setup>import '@focsd-dev/components/focsd-time-field.js';</script>
<template> <focsd-time-field @change="onChange" label="Meeting time" value="09:30" hour-cycle="h23" step="5"></focsd-time-field></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-time-field.js';
// template<focsd-time-field (change)="onChange($event)" label="Meeting time" value="09:30" hour-cycle="h23" step="5"></focsd-time-field><script> import '@focsd-dev/components/focsd-time-field.js';</script>
<focsd-time-field onchange={(e) => console.log(e.target)} label="Meeting time" value="09:30" hour-cycle="h23" step="5"></focsd-time-field>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
name | name | string | — |
disabled | disabled | boolean | false |
required | required | boolean | false |
readonly | readOnly | boolean | false |
aria-label | hostAriaLabel | string | null | null |
aria-description | hostAriaDescription | string | null | null |
aria-labelledby | hostAriaLabelledBy | string | null | null |
aria-describedby | hostAriaDescribedBy | string | null | null |
label-position | labelPosition | 'top' | 'start' | 'end' | undefined | — |
hint | hint | string | — |
error | error | — | — |
warning | warning | string | undefined | — |
success | success | string | undefined | — |
error-message | errorMessage | string | undefined | — |
warning-message | warningMessage | string | undefined | — |
warning-pattern | warningPattern | string | undefined | — |
label | label | string | — |
value | value | string | — |
hour-cycle | hourCycle | '' | 'h12' | 'h23' | — |
step | step | number | 1 |
min | min | string | — |
max | max | string | — |
locale | locale | string | — |
Methods
| Method | Description |
|---|---|
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
| Event | Description |
|---|---|
input | Fired on every user edit of the value. |
change | Fired 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).
| Part | Description |
|---|---|
divider | The ":" between hours and minutes. |
field | The field element. |
label | The label element. |
layout | The wrapper that places the label beside or above the body. |
body | The field, hint and message. |
hint | The author's hint. |
message | The shown error, warning or success message (also `error`, `warning` or `success`). |
message-icon | The message's icon. |
announcer | The visually hidden status region. |
segment | Each hour, minute or AM/PM segment. |
Accessibility
min,max,valueAsDate,valueAsNumber,stepUp()andstepDown()work as on a native time input;stepis in minutes. Not supported:autocomplete(the segments are not native inputs). Use a native<input type="time">where autofill matters.- A labeled
role="group"ofrole="spinbutton"segments named "Hours", "Minutes" (and "AM/PM" in 12-hour mode), each witharia-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, fieldsetdisabledand back/forward restore.
Keyboard
| Key | Action |
|---|---|
| Arrow Up / Down | Change the segment |
| Digits | Type a value; moves on when complete |
| Arrow Left / Right | Previous / next segment |
| A / P (AM/PM segment) | Set AM / PM |
| Backspace / Delete | Clear the segment |
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.