DateTime Picker

A time, or a date and a time, typed into segments or picked from a list.

Category
Forms
Access
Free with an account
Source
508 lines · one file
States
6 drawn

The decision inside it

Nothing is sent until the time is whole

A half-typed time stays inside the field, so your form never receives midnight because someone typed one digit. The value is set with setHours on a copy of the day, so a daylight-saving day keeps the time the reader typed.

When to use it

Use DateTime Picker for a time, or a date and a time together: typed segments with arrow-key stepping, 12 or 24 hours, a minute step, and a time-zone label. For a date alone, use Date Picker.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Liro's DateTime Picker for this.
Install it: npx shadcn@latest add @liro/datetime-picker
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/datetime-picker.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Free components install through the @liro registry with your CLI token: see the Namespaced tab.

Usage

components/schedule-call.tsx
"use client";

import * as React from "react";
import { DateTimePicker } from "@/components/ui/datetime-picker";
import { Field } from "@/components/ui/field";

export function ScheduleCall() {
  const [at, setAt] = React.useState<Date | null>(null);
  return (
    <Field label="Call time">
      <DateTimePicker value={at} onValueChange={setAt} hourCycle={12} minuteStep={15} timezone="Europe/London" clearable />
    </Field>
  );
}

API reference

“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

TypeNotes
mode"time" | "datetime" No"time" for a time alone, "datetime" for a date and a time. Default "datetime".
valueDate | null NoThe chosen moment, or null for none. Controlled.
defaultValueDate | null NoThe starting value when uncontrolled.
onValueChange(date: Date | null) => void NoCalled with a complete Date, or null when cleared. Never with a half-typed time.
hourCycle12 | 24 No12 shows AM/PM; 24 does not. Default from the reader's locale.
granularity"hour" | "minute" | "second" NoThe smallest unit shown. Default "minute".
minuteStepnumber NoHow far the arrow keys move the minutes, e.g. 5 or 15. Default 1.
timezonestring NoAn IANA zone shown as a label, e.g. "Europe/London". Not converted.
minDateDate NoEarliest day that can be picked.
maxDateDate NoLatest day that can be picked.
placeholderstring NoShown on the date button when no date is chosen.
clearableboolean NoAdds an × that clears the value.
disabledboolean NoRead-only and dimmed.
size"sm" | "md" | "lg" Nosm, md or lg, matching Input and Button. Default md.
classNamestring No–
idstring No–

Dependencies

npm packages

clsxdate-fnslucide-reacttailwind-merge

Liro foundations, installed alongside it

liro-themecalendarfieldpopover

States

All of them are drawn by the component. None is left for you to design.

  • Empty
  • Date and time
  • Time only
  • 12 hour
  • 24 hour
  • Disabled

Accessibility

  • Keyboard reachable throughout, in visual order
  • Focus trapped in overlays, Escape closes them
  • Focus returns to whatever opened it
  • Live regions announce what changed, not that something did
  • Honours prefers-reduced-motion

Responsive behavior

  • Sizes to its container, not the viewport
  • Usable from 320px up
  • Pointer-based interaction, so trackpad and touch both work
  • No hover-only affordances