Skip to content

Time picker

Pick an hour and minute on a clock dial or by typing, 12- or 24-hour.

import { TimePicker, TimePickerModeToggle, useTimePickerRoom } from '@windmorph/react';

Props

By name or description, across the 24 props below

TimePicker 15 props

  • valuetype Time

    Controlled time (@internationalized/date Time).

  • defaultValuetype Timedefault 12:00

    Initial time when uncontrolled.

  • hourCycletype 12 | 24

    12- or 24-hour clock. Left out, the locale's hour cycle (12 in en-US, 24 in en-GB).

  • modetype "dial" | "input"

    The clock dial, or typed hour and minute fields (controlled).

  • defaultModetype "dial" | "input"default "dial"

    Initial mode when uncontrolled.

  • layouttype "vertical" | "horizontal" | "auto"default "auto"

    vertical stacks the time over the dial; horizontal (landscape) puts them side by side. auto picks vertical when the window is tall enough, horizontal when it is only wide enough, and the typed input when neither fits, so the picker never scrolls (M3 time picker placement and adaptive design).

  • densitytype 0 | -1 | -2 | -3default 0

    Web density of the input mode, 0 to -3: each step takes 4px off the typed hour and minute fields (72px at 0, 60px at -3). The dial keeps its size: M3 doesn't make time pickers denser, since its 48px number targets are part of their accessibility. Left out, the picker takes the density of the nearest ThemeProvider or ThemeScope.

  • idtype string

    The root <div>'s id.

  • reftype Ref<HTMLDivElement>

    Ref to the root <div> element.

Events

  • onChangetype ((value: Time) => void)

    Called with the new time when the user changes it.

  • onModeChangetype ((mode: TimePickerMode) => void)

    Called when the user switches between the dial and the typed input.

Text

  • labelstype Partial<TimePickerLabels>

    Words the picker shows and announces, with English defaults. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

TimePickerModeToggle 9 props

  • modetype "dial" | "input"Required

    The time picker's mode; the toggle switches to the other one.

  • keyboardIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Shown in dial mode. Defaults to Material Symbols' keyboard.

  • clockIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Shown in input mode. Defaults to Material Symbols' schedule (a clock).

  • idtype string

    The icon button's id.

  • reftype Ref<HTMLButtonElement>

    Ref to the icon button.

Events

  • onModeChangetype (mode: TimePickerMode) => voidRequired

    Called with the other mode when the toggle is pressed.

Text

  • labelstype Partial<TimePickerLabels>

    Words the toggle announces (inputMode, dialMode), with English defaults. Takes the same object as the time picker's labels, so one set of words covers both. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Tokens

M3's component tokens as CSS variables. Each is unset until you set it, on :root, a theme or any ancestor, and falls back to the default shown. The root carries data-variant (and data-size where it has sizes), which picks the variables that apply. See Component tokens in the Customisation guide.

Time picker tokens (md-comp-time-picker)
VariableDefaultPaintsCompose
--md-comp-time-picker-clock-dial-colorvar(--md-sys-color-surface-container-highest)The clock dial.TimePickerTokens.ClockDialColor
--md-comp-time-picker-clock-dial-selector-handle-container-colorvar(--md-sys-color-primary)The dial's selector: its handle, track and centre dot.TimePickerTokens.ClockDialSelectorHandleContainerColor
--md-comp-time-picker-time-selector-selected-container-colorvar(--md-sys-color-primary-container)The hour or minute selector being set.TimePickerTokens.TimeSelectorSelectedContainerColor
--md-comp-time-picker-time-selector-unselected-container-colorvar(--md-sys-color-surface-container-highest)The other time selector.TimePickerTokens.TimeSelectorUnselectedContainerColor
--md-comp-time-picker-period-selector-selected-container-colorvar(--md-sys-color-tertiary-container)The chosen AM or PM option.TimePickerTokens.PeriodSelectorSelectedContainerColor
--md-comp-time-picker-period-selector-outline-colorvar(--md-sys-color-outline)The AM / PM selector's 1px border and the line between its options.TimePickerTokens.PeriodSelectorOutlineColor
--md-comp-time-picker-container-colorvar(--md-sys-color-surface-container-high)The dialog panel.TimePickerTokens.ContainerColor
--md-comp-time-picker-container-shapevar(--md-sys-shape-corner-extra-large)The dialog panel's corners.TimePickerTokens.ContainerShape

Hooks

useTimePickerRoom

useTimePickerRoom signature
useTimePickerRoom(): "vertical" | "horizontal" | "none"

Where an auto time picker's dial fits: vertical, horizontal or none.

Returns "vertical" | "horizontal" | "none"

Spec status

Built to the M3 Expressive time picker spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.

  • Time picker dial

    Built

    Variant · Dial, Modes

  • Time picker input

    Built

    Variant · Modes

  • Vertical layout

    Built

    Configuration · Dial

  • Horizontal layout

    Built

    Configuration · Modes

  • 24-hour time picker dial

    Built

    Configuration · Modes

  • Modal, with a dial / input toggle

    Built

    Use case · Modal

  • 24-hour ring layout

    Differs

    00–11 sit on the outer ring and 12–23 on the inner one, as the spec’s image, Compose and Android show; one sentence of the guidelines says even and odd numbers instead.

  • Density of the input mode

    Extension

    density (0 to -3, or the theme's) takes 4px a step off the typed hour and minute fields; the dial keeps its size, since M3 doesn't make time pickers denser.

  • layout="auto" and useTimePickerRoom

    Extension

    Picks the vertical layout, the horizontal one or the input from the window’s room, so the picker never scrolls, as the spec asks.

  • Input validation messages

    Not built

    An out-of-range hour or minute is marked invalid, without a written message yet.

Bundle size

Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.

  • TimePicker, TimePickerModeToggle: 39.7 kB

Differences from Compose

  • 96 × 80px hour and minute selectors in display-large (114px wide on a 24-hour dial), selected primary-container, over a 256px surface-container-highest dial with a 48px primary handle. Input mode has 96 × 72px fields for both clocks.
  • layout="horizontal" puts the time beside the dial, with a 216 × 38px AM / PM selector below it. The default auto picks the vertical layout when the window is tall enough, the horizontal one when it is only wide enough, and the input when neither fits, so the picker never scrolls; useTimePickerRoom() returns that choice for your own layout.
  • On a 24-hour dial, 00–11 are on the outer ring and 12–23 on the inner one, as in the spec's image, Compose and Android (one sentence of the spec says even and odd numbers instead).
  • The AM / PM selector keeps the token's tertiary-container selected colour (Compose's isUpdatedTimepickerToggleEnabled flag would switch it to primary-container). The dial is an SVG, so nothing is positioned.