Yugen UI

TimePicker

TimePicker is a combobox-style input for picking a time from a list or typing it freely.

The list holds times increment minutes apart between startHour and endHour. Type "9", "930", "9h30", "21:15" or "9:30 PM", then press Enter or leave the field to confirm; while you type, the list highlights the nearest time. onTimeChange(event, { selectedTime, selectedTimeText, errorType }) reports "invalid-input" / "out-of-start-bound" / "out-of-end-bound" so you can show the error through <Field>. The default hour cycle follows locale (vi-VN → 24-hour). Shares the input shell (fieldAppearanceClass) and the options with Combobox.
Type 9, 930, 9:30 PM or 21:15, or pick from the list
No time selected

Import

Install from npm, copy the source into your project with @yugen-ui/cli or the shadcn CLI, or import directly when working in this repo.

TSX
// npm install yugen-uiimport { TimePicker, Field, formatTime, parseTimeString, getTimesInRange } from "yugen-ui";

Variants

Each tile is a standalone example: hover to copy, or press Code to see the source.

Working hours, 15-minute steps

startHour / endHour (endHour excluded) limit the list; typing "7" or "19:00" reports an out-of-range error.

Between 1:30 PM and 5:00 PM

minTime / maxTime & dateAnchor

Only the time part is compared; the returned time is set on the date of dateAnchor.

12-hour (SA / CH, AM / PM)

hourCycle="h12" uses the locale's day period labels; locale="en-US" defaults to 12-hour.

Size, appearance & disabled

small 24px, medium 32px, large 40px; appearance as in Input / Combobox.

Usage

Do
  • Wrap it in <Field> and show a message based on the errorType from onTimeChange.
  • Pick an increment (15 / 30 minutes) that keeps the list short; other times can still be typed.
  • Set startHour / endHour or minTime / maxTime instead of checking the value yourself after selection.
Don't
  • Don't use TimePicker for durations ("2 hours 30 minutes"). Use SpinButton.
  • Don't format times differently from one screen to another. Use hourCycle / locale.

Props

Prop · TypeDefaultDescription
value / defaultValueDate | nullDefault: —Selected time (controlled / uncontrolled).
onTimeChange(event, { selectedTime, selectedTimeText, errorType? }) => voidDefault: —Called when an option is picked or typed text is confirmed (Enter / leaving the field).
onValueChange(value: Date | null) => voidDefault: —Called when the selected time changes; null when the field is cleared or the typed text is invalid.
incrementnumberDefault: 30Step between options (minutes).
startHour / endHournumberDefault: 0 / 24First hour (included) and last hour (excluded).
minTime / maxTimeDateDefault: —Earliest / latest time (included, time part only).
hourCycle"h23" | "h12"Default: from locale24-hour, or 12-hour with day period labels.
localestringDefault: "vi-VN"Sets the default hourCycle and the SA/CH, AM/PM labels.
dateAnchorDateDefault: date of value / todayDate the returned time is set on.
formatDateToTimeString(date: Date) => stringDefault: —Custom display format.
appearance"outline" | "underline" | "filled-darker" | "filled-lighter"Default: "outline"Input shell style.
size"small" | "medium" | "large"Default: "medium"Height 24 / 32 / 40px.
disabled / required / id / aria-*—Default: —Passed by Field when wrapped in <Field>.
formatTime / parseTimeString / getTimesInRange / getTimeBoundsErrorhelperDefault: —Pure functions to format a time, parse typed text, generate the time list and check the bounds.

Messages

Text built into the component: labels, aria-labels, screen reader announcements.

English by default. Change it with the messages prop of YugenProvider, by the namespace below; messagesVi has the Vietnamese set. See Interface language.

messages.timePicker

Key · TypeDefault (English)messagesVi
placeholderstring

Placeholder của ô nhập.

Default (English)"Select a time…"messagesVi"Chọn giờ…"
noOptionsstring

Nội dung khi khoảng giờ rỗng.

Default (English)"No matching times"messagesVi"Không có giờ phù hợp"
listLabelstring

aria-label của danh sách giờ khi ô nhập không có nhãn riêng.

Default (English)"Select a time"messagesVi"Chọn giờ"
closeListstring

aria-label nút mũi tên khi danh sách đang mở.

Default (English)"Close time list"messagesVi"Đóng danh sách giờ"
openListstring

aria-label nút mũi tên khi danh sách đang đóng.

Default (English)"Open time list"messagesVi"Mở danh sách giờ"