Time Picker

A time field people type into, with a list of times to pick from.

Installation

  1. Add the registryOnce per project
  2. Add time-picker

Usage

TimePickerInput splits the time into an hour, a minute and, on a 12-hour clock, AM or PM. Each part takes typed digits and moves on once it's filled, so 9, 3, 0, p gives 9:30 PM, and a or p sets AM or PM from any part. Arrow keys step a part up and down, and Backspace clears it. Pasting a time such as 14:30 or 2:30 pm fills every part, and pasting a number such as 45 fills only the focused one. TimePickerContent adds a clock button to the input that opens a list of times, every 15 minutes by default.

The value is a 24-hour HH:mm string, such as "21:30", the format of a native time input. onValueChange gets it once every part is filled in, and null once one is cleared.

Composition

Examples

With a label

Put the picker in a Field with a FieldLabel. The input reads out the field's FieldDescription and FieldError, and turns invalid or disabled with the field. Without a visible label, give the input an aria-label.

We'll nudge you at this time every weekday.

With a date picker

Set a Date Picker beside it for a date and a time. They're the same height in each size.

Guests see it in their own time zone.

To combine their values, set the time on a copy of the date:

Hour cycle

The input follows the hour cycle of its locale, a DayPicker locale like the Date Picker's, which is 12 hours for the default English. hourCycle={24} runs hours from 0 to 23 instead, with no AM or PM. The list writes times the locale's way, and the input puts AM or PM first in locales that do, such as Chinese.

Earliest and latest times

min and max bound the list, and the input turns invalid outside them. step sets the minutes between the times in the list. A min later than max makes a range that runs past midnight, so min="22:00" max="02:00" offers the times from 10:00 PM to 2:00 AM.

Open 9:00 AM to 5:00 PM.

Seconds

granularity="second" adds seconds, and the value becomes HH:mm:ss. Leave out TimePickerContent for an input on its own.

In a form

Give a Field or the picker a name, and the value submits under it as HH:mm, or pass form with a form's id when the picker sits outside it. With required, the form won't submit without a time, which fails as valueMissing. A time outside min and max, or one only partly typed, stops it too, as customError, so a FieldError matching it shows the reason. A form reset brings back defaultValue.

Open 9:00 AM to 5:00 PM.

Sizes

size on the input matches the sizes of buttons, inputs and selects.

Invalid

Set invalid on the Field, and explain the problem with a FieldError.

Disabled

Props

TimePicker takes the props of Popover's root too, such as open and onOpenChange for the list.

The tables leave out className, style and render. Parts built on Base UI take them as its styling and composition guides describe.

TimePicker

TimePickerInput

TimePickerContent