Time field
Hour, minute and AM/PM segments you step with arrow keys or type into.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- Built on native elements
- A named group of spin buttons (Hour, Minute, AM or PM), each with aria-valuenow, aria-valuemin, aria-valuemax and aria-valuetext.
- ArrowUp/ArrowDown step a segment (minutes by the step prop), PageUp/PageDown step further, Home/End jump to the limits, Backspace clears.
- Typing digits fills a segment and moves to the next; A and P set AM and PM.
- Styles in one file:
03-form-fields.css
Import
import '@monoline/css';
import {TimeField} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add time-field
Usage
import {Field, TimeField} from '@monoline/react';
<Field label="Start time">
<TimeField defaultValue="09:30" />
</Field>
Examples
12-hour
24-hour in 15 minute steps
Props
TimeFieldProps
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | – | The time as 24-hour `"HH:mm"` when controlled; `""` means none. Pair with `onValueChange`. |
defaultValue | string | – | The initial time as `"HH:mm"` when uncontrolled. Default none. |
onValueChange | ((value: string) => void) | – | Called with `"HH:mm"` once hour and minute are both set, or `""` when either is cleared. |
hourCycle | 12 | 24 | 12 | Show hours 1-12 with an AM/PM segment (`12`) or 0-23 (`24`). Default 12. |
step | number | 1 | Minutes the arrow keys move by. Default 1. |
disabled | boolean | – | Stops all input. |
invalid | boolean | – | Marks the field as having an error: sets `aria-invalid` and shows the error border. |
name | string | – | Form field name; a hidden input submits the 24-hour `"HH:mm"` value. |
aria-label | string | – | Names the group when it is not inside a Field. Default "Time". |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
| Attribute | Stylesheet |
|---|---|
[aria-checked="true"] | 03-form-fields.css |
[aria-invalid="true"] | 03-form-fields.css |
[aria-pressed="true"] | 03-form-fields.css |
[data-disabled] | time-field.css |
[data-empty] | time-field.css |
CSS classes
| Class | Stylesheet |
|---|---|
.field | 03-form-fields.css |
.field-hint | 03-form-fields.css |
.input | 03-form-fields.css |
.input-bare | 03-form-fields.css |
.input-end | 03-form-fields.css |
.input-lg | 03-form-fields.css |
.input-sm | 03-form-fields.css |
.input-wrap | 03-form-fields.css |
.muted | 03-form-fields.css |
.seg | 03-form-fields.css |
.seg-opt | 03-form-fields.css |
.select | 03-form-fields.css |
.setting | 03-form-fields.css |
.switch | 03-form-fields.css |
.textarea | 03-form-fields.css |
.time-field | time-field.css |
.time-segment | time-field.css |
.time-sep | time-field.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.field {
border-color: var(--accent);
}
.field[aria-checked="true"] {
background: var(--wash);
}
Accessibility
- A named group of spin buttons (Hour, Minute, AM or PM), each with aria-valuenow, aria-valuemin, aria-valuemax and aria-valuetext.
- ArrowUp/ArrowDown step a segment (minutes by the step prop), PageUp/PageDown step further, Home/End jump to the limits, Backspace clears.
- Typing digits fills a segment and moves to the next; A and P set AM and PM.
- ArrowLeft/ArrowRight move between segments and are mirrored in right-to-left.
Keyboard
| Keys | Action |
|---|---|
| ArrowUp / ArrowDown | Step a segment (minutes by the step prop) |
| PageUp / PageDown | Step further |
| Home / End | Jump to the limits |
| Backspace | Clears |
| ArrowLeft / ArrowRight | Move between segments and are mirrored in right-to-left |