Skip to content

    TimePicker

    A field-looking trigger that opens a list of hours and minutes, for picking a time of day in a form. The value is a 24-hour HH:mm string. A date stays on DatePicker, and a date with a time is a DatePicker beside a TimePicker.

    React

    Preview

    Props

    • minuteStep
    • placeholder
    • disabled
    • invalid
    • size
    import { TimePicker } from "@/components/ui/time-picker"
    
    <TimePicker minuteStep={5} placeholder="Pick a time" />

    Usage

    When to use

    • Picking a time of day in a form, with the same field look as DatePicker.
    • Limiting the minutes to a step, such as every 15 minutes.

    When not to use

    • Picking a date or a range of dates. Use DatePicker.
    • Typing a time the user already knows. Use Input.

    Platform support

    What each platform has, from the spec. A selected platform is highlighted.

    NameWebiOSAndroidNote
    valueYesYesYes
    defaultValueYesDeferredDeferredNot generated for iOS and Android.
    onValueChangeYesYesYes
    minuteStepYesYesYes
    placeholderYesYesYes
    disabledYesYesYes
    invalidYesYesYes
    sizeYesYesYes
    modalYesDeferredDeferredNot generated for iOS and Android.
    hourLabelYesYesYes
    minuteLabelYesYesYes
    nameYesNoNoOnly on web. Not generated for iOS and Android.
    sheetTitleNoYesYesOnly on iOS, Android.
    value of keyboard: Space, EnterYesDeferredDeferred
    value of keyboard: ArrowUp / ArrowDownYesDeferredDeferred
    value of keyboard: EscapeYesDeferredDeferred

    Variants

    minuteStep

    Minutes between choices. 5 is every five minutes. 1 lists every minute.

    • 1

    • 5default

    • 15

    • 30

    import { TimePicker } from "@/components/ui/time-picker"
    
    <TimePicker minuteStep={1} placeholder="Pick a time" />
    <TimePicker minuteStep={5} placeholder="Pick a time" />
    <TimePicker minuteStep={15} placeholder="Pick a time" />
    <TimePicker minuteStep={30} placeholder="Pick a time" />

    size

    Trigger height from size-element-*, the same steps as Input and Select: sm 28px, md 32px (the default), lg 36px, xl 44px with a mouse; on touch md is 36px, lg 44px and xl 48px. Match the Input or Button next to it.

    • sm

    • mddefault

    • lg

    • xl

    import { TimePicker } from "@/components/ui/time-picker"
    
    <TimePicker size="sm" minuteStep={5} placeholder="Pick a time" />
    <TimePicker minuteStep={5} placeholder="Pick a time" />
    <TimePicker size="lg" minuteStep={5} placeholder="Pick a time" />
    <TimePicker size="xl" minuteStep={5} placeholder="Pick a time" />

    Examples

    Check-in time

    The trigger has the field look, and the hours and minutes open in a popover.

    Local time at the property.

    import { Field, FieldControl, FieldDescription, FieldLabel } from "@/components/ui/field"
    import { TimePicker } from "@/components/ui/time-picker"
    
    <Field className="w-full max-w-sm">
      <FieldLabel>Check-in time</FieldLabel>
      <FieldControl>
        <TimePicker />
      </FieldControl>
      <FieldDescription>Local time at the property.</FieldDescription>
    </Field>

    Quarter hours

    import { TimePicker } from "@/components/ui/time-picker"
    
    <TimePicker minuteStep={15} defaultValue="09:30" />

    Do and don't

    Do

    • Use TimePicker for a time of day in a form, next to other fields.
    • Name it with a Label pointing at its id.
    • Put a date and a time in two Fields beside each other: DatePicker, then TimePicker.

    Don't

    • Don't use TimePicker for a date or a range of dates. Use DatePicker.
    • Don't use a native time input when the rest of the form uses DatePicker. The trigger should match.
    • Don't put the hour and the minute in two Fields. One TimePicker is the time.

    Props

    NameTypeValuesDefaultDescription
    valuestring--The picked time as HH:mm when you control it. An explicit undefined clears it. Pair it with onValueChange.
    defaultValuestring--The time on first render when you do not control it, as HH:mm. Not generated for iOS and Android.
    onValueChange(value: string) => void--Called with HH:mm once both an hour and a minute are picked.
    minuteStepenum1 | 5 | 15 | 305Minutes between choices. 5 is every five minutes. 1 lists every minute.
    placeholderstring-Pick a timeText shown in the trigger while no time is picked. It also names the dialog when there is no aria-label.
    disabledboolean-falseDisables the trigger.
    invalidboolean-falseMarks the value as wrong: sets aria-invalid, which draws the danger border.
    sizeenumsm | md | lg | xlmdTrigger height from size-element-*, the same steps as Input and Select: sm 28px, md 32px (the default), lg 36px, xl 44px with a mouse; on touch md is 36px, lg 44px and xl 48px. Match the Input or Button next to it.
    modalboolean-falseWhether the open popover blocks interaction with the rest of the page. Not generated for iOS and Android.
    hourLabelstring-HoursName of the hour list.
    minuteLabelstring-MinutesName of the minute list.
    namestring--Form name. The submitted value is HH:mm, on a hidden input. Only on web. Not generated for iOS and Android.
    sheetTitle requiredstring--The name of the Sheet that holds the time wheel. Shown as its title and read by assistive technology. Native only. Only on iOS, Android.

    Anatomy

    PartDescription
    rootThe trigger button: the same field look as DatePicker and Input, in the size you set.
    iconA decorative Tabler clock icon at the start, 16px (20px in xl), secondary.
    labelThe picked time as HH:mm, or the placeholder in secondary text.
    hitAreaTransparent ::before centered on the trigger, never smaller than size-target-min (24px on mouse, 44px on touch), so sm, md and lg stay easy to tap.
    contentThe Popover: a column of hours and a column of minutes.

    Accessibility

    Role: button

    KeysAction
    Space, EnterOn the trigger, opens the popover. On an hour or a minute, picks it.
    ArrowUp / ArrowDownMove through the hours or the minutes. Home and End jump to the first and last.
    EscapeCloses the popover and returns focus to the trigger. A time is sent only when both an hour and a minute are picked.
    • The trigger opens a dialog named by aria-label or the placeholder. Hours and minutes are two listboxes.
    • Picking a minute, once an hour is picked, sends the time and closes. Picking an hour first leaves the popover open.
    • The trigger accepts id, aria-label and aria-describedby, so a Label and a hint can name and describe it like any field.
    • name submits HH:mm on a hidden input. The trigger is a button, so it does not submit the draft.

    Install

    npx werewolf-ui add time-picker

    Run npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.