Skip to content

Early previewhamur is not on npm yet. The components are being built in the open, follow along on GitHub.

UIComponentsReact

Date Picker

A field the reader types a date into, with a button that opens a calendar in a popup to pick it from.

Built on the headless Date Picker.See its API in Docs

Rendered by React 19.3.1

date-picker.tsx

Installation

npx shadcn@4.23.0 add https://hamur.dev/r/react/date-picker.json

It also adds utils, button, calendar, popover. The app needs its setup first: Installation.

Usage

DatePicker holds a DatePickerControl, which is the field's box, and a DatePickerPortal with a DatePickerPositioner, a DatePickerPopup and a DatePickerCalendar for the popup. Inside the control, DatePickerInput draws the segments (month, day and year in the order of the locale), DatePickerClear empties them and DatePickerTrigger opens the popup; each has its icon and its name by default. Name the control (aria-label, or a Field label around the picker). DatePickerPreset sets a date from a function of today (value={(today) => today}) and DatePickerClose closes the popup. The value is an ISO date string; min, max, isDateDisabled, isDateUnavailable, locale, visibleMonths, closeOnSelect and the rest are the headless Date Picker's Root props. A DatePickerCalendar that shows more than one month needs months as well as the Root's visibleMonths.

import {
  DatePicker,
  DatePickerCalendar,
  DatePickerClear,
  DatePickerClose,
  DatePickerControl,
  DatePickerInput,
  DatePickerPopup,
  DatePickerPortal,
  DatePickerPositioner,
  DatePickerPreset,
  DatePickerSegment,
  DatePickerTrigger,
} from '@/components/ui/date-picker'

Examples

Default

An input with the clear and calendar buttons beside it.

Its preview and code are at the top of the page.

shadcn has no date picker item, only a page that composes a Popover and its Calendar around an outline button that shows the formatted date. This item follows that composition with the headless parts: the popup is the Popover's content with w-auto p-0 around the Calendar's markup, and the field is the Input's box with ghost icon buttons in it. It differs in these places:

- The field is typed into: three segments with arrow-key stepping, not a button that shows a formatted date. The popup is an addition the reader can skip. - The root is a DatePicker with the value, the limits and the popup state of the headless Date Picker (open, onOpenChange, value, onValueChange), in place of a Popover with a Calendar inside; there is no mode, and the value is a string, not a Date. - The popup returns focus to the trigger, closes on a pressed day (closeOnSelect) and is named by the calendar's label. - Each name is one Base UI part, so a part can be left out or replaced; DatePickerPreset and DatePickerClose have no counterpart in shadcn's page.

API reference

The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on Date Picker's API reference.