Time input
A time typed in segments: hours, minutes, optional seconds and AM or PM, on the locale's clock or one you set. Use it for a meeting time or an alert window. For a date use the date input, which works the same way.
Install
npx shadcn@latest add @thrum-pro/time-inputThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | null | – | The time as "14:30", or "14:30:15" with seconds, when the parent holds it. Use it with onValueChange. |
defaultValue | string | null | Default null | The time at first, when the field holds it itself. |
onValueChange | (value: string | null) => void | – | Called with the time on a 24-hour clock once every segment is filled, and with null when one is cleared. |
seconds | boolean | Default false | Show a seconds segment. The value then carries seconds. |
hourCycle | 12 | 24 | – | 12 shows an AM/PM segment and hours 1 to 12, 24 runs the hours from 0 to 23. Defaults to the locale's clock. |
step | number | Default 1 | Minutes per arrow press in the minutes segment. Typed minutes are kept as typed. |
min | string | null | – | The earliest valid time, "HH:mm". An earlier one is kept and marks the field invalid. |
max | string | null | – | The latest valid time, "HH:mm". A later one is kept and marks the field invalid. |
locale | string | Default "en-US" | Sets the segment order, the AM and PM words, the segment names read out and the default clock. |
name | string | – | The field name in a form. A hidden input submits the time as 14:30, or an empty string. |
size | "sm" | "md" | "lg" | Default "md" | sm is 28 pixels tall, md 32, lg 40. |
disabled | boolean | Default false | Dimmed, skipped by Tab, and cannot be changed. |
readOnly | boolean | Default false | Focusable and read out, but the keys do not change it. |
required | boolean | Default false | Sets aria-required on every segment. Check for a null value before you submit. |
invalid | boolean | Default false | Marks the field invalid for a reason of your own. A time outside min and max marks it on its own. |
sound | boolean | Default true | Play a soft tick when stepping a segment with arrow, Page Up/Down or Home/End keys, if the visitor has sound on. |
className | string | – | Extra classes for the field, merged last. It fills its container by default. |
timeError(time, min, max) | "min" | "max" | null | – | Exported helper: which limit a time breaks, for the message you show beside the field. |
Motion and sound
Motion
- The border colour fades over 150 ms when the field turns invalid.
- Reduced motion: it changes at once.
Sound
- A subtle tick when stepping a segment with ↑, ↓, Page Up, Page Down, Home or End. Typing digits is silent.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- The field is a group of spin buttons, one per segment, each with its value, its limits and its name in the locale's words (hour, minute).
- Name the group with aria-labelledby or aria-label, as the example does.
- The AM/PM segment reads its word (AM, PM), not a number. Typing an hour on a 12-hour clock fills it with AM until you change it.
- A time outside min and max sets aria-invalid on every segment and turns the border red; point aria-describedby at your message so it is read too.
- Each segment is editable text, so a phone opens its keyboard. Pasting is ignored.
| Keys | Action |
|---|---|
| Tab / Shift Tab | Move to the next or previous segment, then out of the field. |
| 0 to 9 | Fill the segment. It moves on once another digit could not fit: after 3 in a 24-hour hour, after two digits in the minutes. |
| A / P | In the AM/PM segment: set AM or PM, by the first letter of the locale's words. |
| ↑ / ↓ | Step the segment, round from the last value to the first. Minutes move by step. In the AM/PM segment, switch. |
| Page Up / Page Down | Step the segment by ten steps. |
| Home / End | The lowest or highest value of the segment. |
| ← / → | Move to the segment before or after. |
| Backspace / Delete | Clear the segment. Backspace on an empty segment moves to the one before. |
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/time-input.tsx- Packages
- None
- Brings along
- Date input
Changelog
- 1.0.0 · 2026-12-03First release.