TimePicker

A composable time picker that pairs a segmented time input with a popover containing wheel-based spinbutton columns. Values are HH:mm or HH:mm:ss strings, with null as the empty state.

hhmma. m.

Value: null

Anatomy

TimePicker.Root owns the value and open state. TimePicker.Input renders locale-resolved segments, TimePicker.Trigger opens the popover, and TimePicker.Clock resolves the visible wheel columns from root state (granularity, hourCycle) in stable order: hour → minute? → second? → dayPeriod?. The column snippet customizes each wheel; omit it for default rendering.

<script>
	import { TimePicker } from '@human-kit/ui/timepicker';
</script>

<TimePicker.Root>
	<TimePicker.Input aria-label="Time input">
		{#snippet children(segment)}
			<TimePicker.Segment {segment} />
		{/snippet}
	</TimePicker.Input>
	<TimePicker.Trigger />

	<TimePicker.Popover>
		<TimePicker.Clock />
	</TimePicker.Popover>
</TimePicker.Root>

Min and max bounds

minValue and maxValue constrain both the typed input and the wheels. Out-of-range wheel items are rendered with data-disabled; typed out-of-range values mark the input invalid instead of being auto-corrected. Midnight-wrapping ranges are not supported.

930AM

Time constrained between 09:00 and 17:00 — value: 09:30

12-hour cycle

Set hourCycle={12} to render an AM/PM segment and a day-period wheel column. Values are always normalized to 24-hour strings internally — the 12-hour rendering only affects the UI.

245PM

Emitted value stays 24-hour: 14:45

Usage guidelines

  • Use value with onChange for controlled state and defaultValue for uncontrolled state; the empty state is null.
  • granularity controls the editable units: 'hour', 'minute' (default), or 'second'. granularity="hour" emits HH:00 values.
  • Use hourStep, minuteStep, and secondStep to restrict selectable values to increments.
  • Use open / defaultOpen / onOpenChange to control the popover; wheel selection commits immediately on snap.
  • TimePicker.Popover forwards Popover.Content props such as placement (default bottom), offset, and shouldFlip.
  • Wrap in a LocaleProvider to localize segment order, day-period labels, and the default hour cycle.

Accessibility

  • Segment accessible names are resolved automatically from the active locale.
  • TimePicker.Input exposes aria-invalid and data-invalid when the current segment draft is not committable.
  • Each wheel column exposes role="spinbutton" with aria-valuenow, aria-valuetext, aria-valuemin, and aria-valuemax.
  • Inside the popover, ArrowUp/ArrowDown step the focused column, ArrowLeft/ArrowRight move between columns, and Home/End jump to the column edges.
  • Popover focus defaults to the first wheel column; Escape and outside presses close it.

API reference

Root

The stateful container. Owns the committed time value, the popover open state, and the granularity/hour-cycle configuration shared by the input and clock.

Prop Type Default

* required. Native HTML attributes of the underlying element are also accepted.

Input

The segmented time input. Iterates the locale-resolved segments and passes each to the children snippet.

Prop Type Default

* required. Native HTML attributes of the underlying element are also accepted.

Data attribute Description
data-disabled Present when the time picker is disabled.
data-focus-visible Present while focus should be visibly indicated (keyboard modality).
data-focus-within Present while a segment inside the input has focus.
data-invalid Present while the current segment draft is not committable.
data-open Present while the popover is open.
data-readonly Present when the time picker is readonly.

Segment

One editable or literal segment of the time (hour, minute, second, day period, or separator). Supports typing and arrow-key stepping.

Prop Type Default

* required. Native HTML attributes of the underlying element are also accepted.

Data attribute Description
data-focus-visible Present while focus should be visibly indicated (keyboard modality).
data-focused Present while the segment has focus.
data-placeholder Present while the segment shows its placeholder instead of a value.
data-time-picker-segment Identifies a time picker segment element.
data-type The segment type, e.g. 'hour', 'minute', 'second', 'dayPeriod', or 'literal'.

Trigger

Button that opens and closes the clock popover.

Prop Type Default

* required. Native HTML attributes of the underlying element are also accepted.

Data attribute Description
data-focus-visible Present while focus should be visibly indicated (keyboard modality).
data-focused Present while the trigger has focus.

Popover

The floating panel that hosts the clock. Forwards Popover.Content props (placement, offset, shouldFlip, …); open state, trigger wiring, and id are controlled internally. Placement defaults to bottom and initial focus lands on the first wheel column.

Prop Type Default

* required. Native HTML attributes of the underlying element are also accepted.

Clock

The wheel surface inside the popover. Resolves visible columns from root state (granularity, hourCycle) in stable order: hour → minute? → second? → dayPeriod?.

Prop Type Default

* required. Native HTML attributes of the underlying element are also accepted.

Data attribute Description
data-clock Identifies the clock element.

WheelColumn

One scrollable wheel (role="spinbutton") for one editable segment: hour, minute, second, or dayPeriod.

Prop Type Default

* required. Native HTML attributes of the underlying element are also accepted.

Data attribute Description
data-focus-visible Present while focus should be visibly indicated (keyboard modality).
data-focus-within Present while the column contains focus.
data-wheel-highlight Identifies the column's central highlight band.
data-wheel-spacer Identifies the padding spacers that let edge items reach the center.

WheelItem

Headless item inside a wheel column. Renders one option and exposes its state through data attributes, leaving all visual styling to consumers.

Prop Type Default

* required. Native HTML attributes of the underlying element are also accepted.

Data attribute Description
data-centered Present while the item sits in the center of the wheel.
data-disabled Present when the item cannot be selected (out of range or stepped out).
data-selected Present when the item is the committed value for its column.
data-type The segment type of the item's column.
data-value The option value the item represents.
data-wheel-item Identifies a wheel item element.