Skip to content

Time Input

A time field typed one part at a time, like a native time input.

Installation

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

Usage

TimeInput splits the time into parts: an hour, a minute and, on a 12-hour clock, AM or PM. Each part accepts typed digits and moves to the next part once it's filled, so typing 9, 3, 0, p gives 9:30 PM. Typing a or p in any part sets AM or PM, and a :, . or space moves to the next part early. The arrow keys step a part up and down, Page Up and Page Down step the hour by 2 and the minute by 15, and Backspace clears the part. Pasting a time such as 14:30, 2:30 pm or 1430 fills every part, and pasting a number such as 45 fills only the focused part.

The value is a 24-hour HH:mm string, such as "21:30", the same format as a native time input. onValueChange receives the value once every part is filled in, and null once any part is cleared. To also offer a list of times to pick from, use a Time Picker, which is built on Time Input.

Examples

With a label

Put the input in a Field with a FieldLabel. Screen readers read the field's FieldDescription and FieldError with the input, and the input turns invalid or disabled with the field. Without a visible label, give it an aria-label.

Rings every day.

Hour cycle

The input follows the hour cycle of its locale, a BCP 47 tag such as "de-DE". The default, "en-US", uses a 12-hour clock. hourCycle={24} runs hours from 0 to 23 instead, with no AM or PM. In locales that put AM or PM first, such as Chinese, the input does too.

Earliest and latest times

The input turns invalid outside min and max. A min later than max makes a range that runs past midnight, so min="20:00" max="02:00" accepts times from 8:00 PM to 2:00 AM.

Between 8:00 PM and 2:00 AM.

Seconds

granularity="second" adds seconds, and the value becomes HH:mm:ss.

Labels

labels replaces the input's built-in text, the parts' accessible names and its validation messages, so you can translate the input into another language. Pass only the labels you want to change.

In a form

Give a Field or the input a name, and the value submits under it as HH:mm. Pass form with a form's id when the input sits outside the form. With required, the form won't submit without a time, failing validation with valueMissing. A time outside min and max, or a partly typed one, also blocks submission, failing with customError. A FieldError that matches customError shows the reason, in the words of labels. A form reset restores defaultValue.

We seat from 5:00 PM to 10:30 PM.

Sizes

size matches the sizes of Button, Input and Select.

Invalid

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

Disabled

Props

Children render at the end of the input, where Time Picker puts the button that opens its list. The file also exports parseTime and formatTime, which parse and format values in the HH:mm format.

Base UI's styling (opens in a new tab) and composition (opens in a new tab) guides say more about className, style and render.

TimeInput

TimeInputLabels

labels takes any of these, and keeps the English default for the rest.

useTimeFormat

useTimeFormat(locale?, options?) takes a BCP 47 tag, as TimeInput's locale does, and these options:

It returns: