TimePicker
A field-looking trigger that opens a list of hours and minutes, for picking a time of day in a form. The value is a 24-hour HH:mm string. A date stays on DatePicker, and a date with a time is a DatePicker beside a TimePicker.
Preview
Usage
When to use
- Picking a time of day in a form, with the same field look as DatePicker.
- Limiting the minutes to a step, such as every 15 minutes.
When not to use
- Picking a date or a range of dates. Use DatePicker.
- Typing a time the user already knows. Use Input.
Platform support
What each platform has, from the spec. A selected platform is highlighted.
| Name | Web | iOS | Android | Note |
|---|---|---|---|---|
| value | Yes | Yes | Yes | |
| defaultValue | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| onValueChange | Yes | Yes | Yes | |
| minuteStep | Yes | Yes | Yes | |
| placeholder | Yes | Yes | Yes | |
| disabled | Yes | Yes | Yes | |
| invalid | Yes | Yes | Yes | |
| size | Yes | Yes | Yes | |
| modal | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| hourLabel | Yes | Yes | Yes | |
| minuteLabel | Yes | Yes | Yes | |
| name | Yes | No | No | Only on web. Not generated for iOS and Android. |
| sheetTitle | No | Yes | Yes | Only on iOS, Android. |
| value of keyboard: Space, Enter | Yes | Deferred | Deferred | |
| value of keyboard: ArrowUp / ArrowDown | Yes | Deferred | Deferred | |
| value of keyboard: Escape | Yes | Deferred | Deferred |
Variants
minuteStep
Minutes between choices. 5 is every five minutes. 1 lists every minute.
size
Trigger height from size-element-*, the same steps as Input and Select: sm 28px, md 32px (the default), lg 36px, xl 44px with a mouse; on touch md is 36px, lg 44px and xl 48px. Match the Input or Button next to it.
Examples
Check-in time
The trigger has the field look, and the hours and minutes open in a popover.
Quarter hours
Do and don't
Do
- Use TimePicker for a time of day in a form, next to other fields.
- Name it with a Label pointing at its id.
- Put a date and a time in two Fields beside each other: DatePicker, then TimePicker.
Don't
- Don't use TimePicker for a date or a range of dates. Use DatePicker.
- Don't use a native time input when the rest of the form uses DatePicker. The trigger should match.
- Don't put the hour and the minute in two Fields. One TimePicker is the time.
Props
| Name | Type | Values | Default | Description |
|---|---|---|---|---|
| value | string | - | - | The picked time as HH:mm when you control it. An explicit undefined clears it. Pair it with onValueChange. |
| defaultValue | string | - | - | The time on first render when you do not control it, as HH:mm. Not generated for iOS and Android. |
| onValueChange | (value: string) => void | - | - | Called with HH:mm once both an hour and a minute are picked. |
| minuteStep | enum | 1 | 5 | 15 | 30 | 5 | Minutes between choices. 5 is every five minutes. 1 lists every minute. |
| placeholder | string | - | Pick a time | Text shown in the trigger while no time is picked. It also names the dialog when there is no aria-label. |
| disabled | boolean | - | false | Disables the trigger. |
| invalid | boolean | - | false | Marks the value as wrong: sets aria-invalid, which draws the danger border. |
| size | enum | sm | md | lg | xl | md | Trigger height from size-element-*, the same steps as Input and Select: sm 28px, md 32px (the default), lg 36px, xl 44px with a mouse; on touch md is 36px, lg 44px and xl 48px. Match the Input or Button next to it. |
| modal | boolean | - | false | Whether the open popover blocks interaction with the rest of the page. Not generated for iOS and Android. |
| hourLabel | string | - | Hours | Name of the hour list. |
| minuteLabel | string | - | Minutes | Name of the minute list. |
| name | string | - | - | Form name. The submitted value is HH:mm, on a hidden input. Only on web. Not generated for iOS and Android. |
| sheetTitle required | string | - | - | The name of the Sheet that holds the time wheel. Shown as its title and read by assistive technology. Native only. Only on iOS, Android. |
Anatomy
| Part | Description |
|---|---|
| root | The trigger button: the same field look as DatePicker and Input, in the size you set. |
| icon | A decorative Tabler clock icon at the start, 16px (20px in xl), secondary. |
| label | The picked time as HH:mm, or the placeholder in secondary text. |
| hitArea | Transparent ::before centered on the trigger, never smaller than size-target-min (24px on mouse, 44px on touch), so sm, md and lg stay easy to tap. |
| content | The Popover: a column of hours and a column of minutes. |
Accessibility
Role: button
| Keys | Action |
|---|---|
| Space, Enter | On the trigger, opens the popover. On an hour or a minute, picks it. |
| ArrowUp / ArrowDown | Move through the hours or the minutes. Home and End jump to the first and last. |
| Escape | Closes the popover and returns focus to the trigger. A time is sent only when both an hour and a minute are picked. |
- The trigger opens a dialog named by aria-label or the placeholder. Hours and minutes are two listboxes.
- Picking a minute, once an hour is picked, sends the time and closes. Picking an hour first leaves the popover open.
- The trigger accepts id, aria-label and aria-describedby, so a Label and a hint can name and describe it like any field.
- name submits HH:mm on a hidden input. The trigger is a button, so it does not submit the draft.
Install
npx werewolf-ui add time-pickerRun npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.