compacto-ui

Search documentation

Jump to a page or a component.

DatePicker

Field-shaped trigger that opens the calendar in a popover. One Date in and out.

peer: react-day-picker

Preview

Installation

No install — ask an AI agent to copy this component from registry.json, then pnpm add react-day-picker.

import { DatePicker } from "@/components/ui/date-picker";

Notes

  • Optional peer: react-day-picker (through calendar).
  • One Date in and out. The "HH:mm" plumbing Calendar needs for its time column stays inside — you never see getCalendarTime / setCalendarTime.
  • Closes on the pick that completes the value: the day for date, the slot for time, and the slot for datetime too — picking a day there leaves it open, since the time is still to come.
  • Under granularity="time" with no value yet, the slot lands on today. A time needs a day to be a moment.
  • Under datetime, a day picked before any slot reads as 12:00 AM in the trigger until the slot is picked — the value really is midnight on that day.
  • The trigger is a borderless, filled Button (variant secondary): a flat block that reads as a control to press, with no hairline competing with the popover's edge. Pass variant="outline" when it must line up with text inputs. It sizes to its content; pass a width in className when it must fill something.
  • Single value only. A range picker is a different control, not a mode of this one.
  • Derives ${testId}-calendar for the calendar inside; its days and slots derive from that in turn.

Props

The props worth knowing. Everything else passes straight through to the underlying element, including className, which is merged last so it always wins.

PropTypeDefaultDescription
valueDate | undefined—The picked moment.
onValueChange(value: Date | undefined) => void—Next value; undefined when the day is deselected.
granularity"date" | "time" | "datetime""date"Passed to the calendar; also picks the glyph, placeholder and format.
placeholderstringper granularityTrigger copy with no value. Pass a translated string.
formatValue(value: Date) => stringlocale medium date / short timeTrigger copy from a value.
calendarPropsCalendar props—timeStart, timeEnd, timeStep, timeDisabled, disabled… for the calendar inside.
align"start" | "center" | "end""start"Popover alignment against the trigger.