Loading component…
Loading component…
A time of day you type or pick
To reuse this local React demo, copy all files from the Code tab into the same folder, then import TimePicker from ./time-picker.
import { useState } from "react";
import { TimePicker } from "@/components/ui/time-picker";
export function RunAt() {
const [time, setTime] = useState<string | null>("09:30");
return (
<TimePicker
label="Run at"
value={time}
onChange={setTime}
step={15}
hint="Every weekday, in your time zone."
name="runAt"
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| value | string \| null | The chosen time as "HH:mm" (24 h, like a native time input) – makes it controlled; null shows the placeholder | |
| defaultValue | string \| null | null | Starting time when uncontrolled |
| onChange | (value: string \| null) => void | Called with "HH:mm" when a time is picked or typed, or null when the field is cleared | |
| step | number | 15 | Minutes between the times in the list, counted from min – typing can still set any minute |
| min | string | The earliest time, "HH:mm" – the list starts here, earlier typed times are put back | |
| max | string | The latest time, "HH:mm" – ignored when it lies before min | |
| hourCycle | 12 \| 24 | 9:30 PM or 21:30 – by default the locale's | |
| locale | string | BCP 47 locale for how times are written – the browser's by default; its own AM / PM words can be typed too | |
| placeholder | string | Shown in gray while nothing is chosen – by default 9:00 in the right format, as an example | |
| label | ReactNode | Shown above the field and used as the list's name | |
| hint | ReactNode | A quiet line under the field – the error takes its place while there is one | |
| error | ReactNode | Marks the field invalid (red edge and a faint red fill, aria-invalid) and shows the message where the hint was | |
| optional | boolean | false | Adds "Optional" next to the label |
| size | "sm" \| "md" \| "lg" | "md" | 32 · 36 · 40px high, like the Text Field; taller on touch screens |
| disabled | boolean | false | Dims the field and ignores input |
| name | string | Sends "HH:mm" with a form, through a hidden input | |
| required | boolean | Sets aria-required – check it on submit like any other field | |
| aria-label | string | Accessible name when there is no visible label | |
| className | string | Extra class on the wrapper, e.g. a fixed width in a settings row | |
| ref | Ref<HTMLInputElement> | The text input – focus it after a validation error |
Fills its container – about 120px is enough; the list is as wide as the field
The list opens where there is room and stays inside the window; it lives in the top layer, so a card's overflow never cuts it
Touch screens get 40px rows and 16px text (no zoom on iOS); dark mode built in via .dark or data-theme="dark" on an ancestor
@import "tailwindcss"; in your main CSS file.