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
TimePicker 15 props
Controlled time (
@internationalized/dateTime).Initial time when uncontrolled.
12- or 24-hour clock. Left out, the locale's hour cycle (12 in en-US, 24 in en-GB).
The clock dial, or typed hour and minute fields (controlled).
Initial mode when uncontrolled.
verticalstacks the time over the dial;horizontal(landscape) puts them side by side.autopicks 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).Web density of the input mode,
0to-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 nearestThemeProviderorThemeScope.The root
<div>'s id.Ref to the root
<div>element.
Events
Called with the new time when the user changes it.
Called when the user switches between the dial and the typed input.
Text
Words the picker shows and announces, with English defaults. A
LabelsProvidersets them for the whole app.Name of the hour selector and field.
Name of the minute selector and field.
The AM option.
The PM option.
Name of the AM / PM selector.
Name of the dial.
TimePickerModeToggle's name in dial mode.TimePickerModeToggle's name in input mode.labels.dialValuetype(value: string, total: number, unit: "hours" | "minutes") => stringdefault${value} ${unit} of ${total}Name of a number on the dial (M3: "{Value} Hours or minutes of {Total}"), e.g. "7 hours of 12" or "35 minutes of 60".
valueis the number as the dial shows it ("05"), so the name holds the visible text (WCAG 2.5.3).
Classes for the root element, merged with
classNames.root; consumer classes win.Inline styles for the root element.
Classes for each part, by slot.
The picker's root;
classNameis merged here too.The hour and minute: selectors in dial mode, text fields in input mode.
The labels under the input mode's fields ("Hour", "Minute").
The colon between the hour and the minute.
The AM / PM selector.
Each of the AM / PM selector's options.
The clock dial (dial mode): its face, numbers and hand are drawn inside it.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
TimePickerModeToggle 9 props
The time picker's mode; the toggle switches to the other one.
Shown in dial mode. Defaults to Material Symbols' keyboard.
Shown in input mode. Defaults to Material Symbols' schedule (a clock).
The icon button's id.
Ref to the icon button.
Events
Called with the other mode when the toggle is pressed.
Text
Words the toggle announces (
inputMode,dialMode), with English defaults. Takes the same object as the time picker'slabels, so one set of words covers both. ALabelsProvidersets them for the whole app.Name of the hour selector and field.
Name of the minute selector and field.
The AM option.
The PM option.
Name of the AM / PM selector.
Name of the dial.
TimePickerModeToggle's name in dial mode.TimePickerModeToggle's name in input mode.labels.dialValuetype(value: string, total: number, unit: "hours" | "minutes") => stringdefault${value} ${unit} of ${total}Name of a number on the dial (M3: "{Value} Hours or minutes of {Total}"), e.g. "7 hours of 12" or "35 minutes of 60".
valueis the number as the dial shows it ("05"), so the name holds the visible text (WCAG 2.5.3).
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.
| Variable | Default | Paints | Compose |
|---|---|---|---|
--md-comp-time-picker-clock-dial-color | var(--md-sys-color-surface-container-highest) | The clock dial. | TimePickerTokens.ClockDialColor |
--md-comp-time-picker-clock-dial-selector-handle-container-color | var(--md-sys-color-primary) | The dial's selector: its handle, track and centre dot. | TimePickerTokens.ClockDialSelectorHandleContainerColor |
--md-comp-time-picker-time-selector-selected-container-color | var(--md-sys-color-primary-container) | The hour or minute selector being set. | TimePickerTokens.TimeSelectorSelectedContainerColor |
--md-comp-time-picker-time-selector-unselected-container-color | var(--md-sys-color-surface-container-highest) | The other time selector. | TimePickerTokens.TimeSelectorUnselectedContainerColor |
--md-comp-time-picker-period-selector-selected-container-color | var(--md-sys-color-tertiary-container) | The chosen AM or PM option. | TimePickerTokens.PeriodSelectorSelectedContainerColor |
--md-comp-time-picker-period-selector-outline-color | var(--md-sys-color-outline) | The AM / PM selector's 1px border and the line between its options. | TimePickerTokens.PeriodSelectorOutlineColor |
--md-comp-time-picker-container-color | var(--md-sys-color-surface-container-high) | The dialog panel. | TimePickerTokens.ContainerColor |
--md-comp-time-picker-container-shape | var(--md-sys-shape-corner-extra-large) | The dialog panel's corners. | TimePickerTokens.ContainerShape |
Hooks
useTimePickerRoom
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.
| Item | Status | Details |
|---|---|---|
| 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. |
Time picker input
BuiltVariant · Modes
Vertical layout
BuiltConfiguration · Dial
Horizontal layout
BuiltConfiguration · Modes
24-hour time picker dial
BuiltConfiguration · Modes
Modal, with a dial / input toggle
BuiltUse case · Modal
24-hour ring layout
Differs00–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
Extensiondensity(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.
Extensionlayout="auto"anduseTimePickerRoomPicks 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 builtAn 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), selectedprimary-container, over a 256pxsurface-container-highestdial with a 48pxprimaryhandle. 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 defaultautopicks 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-containerselected colour (Compose'sisUpdatedTimepickerToggleEnabledflag would switch it toprimary-container). The dial is an SVG, so nothing is positioned.