GitHub

Time Picker

A typed, segmented time field with wheels, for one time or a start and end.

TimePicker is a segmented field you can type into, with wheel columns in a popover (a bottom sheet on phones). Values are plain "HH:mm" strings, or "HH:mm:ss" with seconds. They have no date or time zone, so they go straight into forms, URLs and APIs. range picks a start and an end.

Loading example…

Installation

pnpm dlx shadcn@latest add draco-china/sui/time-picker

Usage

import { TimePicker } from "@workspace/ui/components/time-picker";

const [time, setTime] = useState<string>();

<TimePicker aria-label="Alarm" value={time} onValueChange={setTime} />;

The value is always 24-hour, even when the field shows a 12-hour clock.

Range

range takes and reports { from?: string; to?: string }. Each end has its own segments and wheels; on phones the start's wheels sit above the end's, as in Date Picker. The ends keep the order they were set in: an end before the start crosses midnight, as in 22:00 ~ 02:00.

Loading example…

Options

seconds adds a seconds segment and wheel. step sets the minute step for the wheel and the arrow keys; typed minutes stay exact. hourCycle ("h12" or "h23") overrides the locale and adds an AM/PM segment and wheel in 12-hour mode.

Loading example…

Typing and accessibility

Typing works as in Date Picker: digits fill segments, arrows step them, and Backspace clears them. name submits the time string through a hidden input (two inputs in range mode). Supports disabled, aria-invalid, labels, glass, and frosted.

API reference

PropTypeDefault / behavior
rangebooleanfalse.
value, defaultValuestring or TimeRangeDepends on range.
onValueChange(value) => voidReports undefined when empty or unfinished.
secondsbooleanfalse.
stepnumber1 minute.
hourCycle"h12" | "h23"Follows locale.
locale, labelsstring, DateTimeLabelOverridesAs in Date Picker.
name, id, disabledForm name, first segment id, disabled state.
prefixReactNodeA label inside the field, before the value, as filter rows show it; still name the field with aria-label.
glass, frostedboolean | GlassConfig, booleanApplies to the field and wheels.

Exports TimePicker, TimePickerProps, TimeValue, TimeRange, HourCycle, dateTimeLabels, and dateTimeLabelsZhCN.