Playground

Time picker

Pick a time of day with hour, minute and AM/PM segments, using the browser's own control.

  • Built on native elements
  • Native input type="time": the browser exposes hour, minute and AM/PM as spinbuttons.
  • ArrowUp/ArrowDown change a segment, ArrowLeft/ArrowRight or Tab move between segments, typing digits fills one.
  • The control takes its name from a label or aria-label; min, max and step are passed through.
  • Styles in one file: 03-form-fields.css

Import

import '@monoline/css';
import {TimePicker} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add time-picker

Usage

import {Field, TimePicker} from '@monoline/react';

<div style={{maxWidth: '200px'}}>
  <Field label="Start time">
    <TimePicker defaultValue="09:30" />
  </Field>
</div>

Examples

Start time

Every 15 minutes

Props

TimePickerProps

PropTypeDefaultDescription
valuestring–24-hour "HH:mm" (or "HH:mm:ss" when `step` is under 60), or '' for no time.
defaultValuestring''The initial time as 24-hour "HH:mm" when uncontrolled. Default empty.
onValueChange((value: string) => void)–Called with the new time as 24-hour "HH:mm" (or '' when cleared).
size"sm" | "md" | "lg"'md'`md` (default), `sm` for dense layouts or `lg` for prominent forms. Heights match Button, Input and Select at each size.
invalidboolean–Marks the control invalid (`aria-invalid`). A surrounding Field sets this from its `error`.

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[aria-checked="true"]03-form-fields.css
[aria-invalid="true"]03-form-fields.css
[aria-pressed="true"]03-form-fields.css

CSS classes

ClassStylesheet
.field03-form-fields.css
.field-hint03-form-fields.css
.input03-form-fields.css
.input-bare03-form-fields.css
.input-end03-form-fields.css
.input-lg03-form-fields.css
.input-sm03-form-fields.css
.input-wrap03-form-fields.css
.muted03-form-fields.css
.seg03-form-fields.css
.seg-opt03-form-fields.css
.select03-form-fields.css
.setting03-form-fields.css
.switch03-form-fields.css
.textarea03-form-fields.css
.time-pickertime-picker.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

  • Native input type="time": the browser exposes hour, minute and AM/PM as spinbuttons.
  • ArrowUp/ArrowDown change a segment, ArrowLeft/ArrowRight or Tab move between segments, typing digits fills one.
  • The control takes its name from a label or aria-label; min, max and step are passed through.

Keyboard

KeysAction
ArrowUp / ArrowDownChange a segment
ArrowLeft / ArrowRight / TabMove between segments, typing digits fills one