Skip to content
All components
Forms

Date picker

Choose a single date or a date range from a calendar popup attached to a labelled form-field trigger.

A single date or a range from a calendar popup, with locale-aware trigger text.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add date-picker

Then import it from @/components/ui/date-picker. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Single date

Choose one weekday date from a labelled trigger with an associated hint. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { DatePicker } from "@/components/ui/date-picker"
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

const exampleMonth = new Date(2026, 9, 1)

export function DatePickerSingleDate() {
  const id = React.useId()
  const [date, setDate] = React.useState<Date | undefined>()
  
  
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel id={`${id}-date-label`} htmlFor={`${id}-date`}>
          Appointment date
        </FieldLabel>
        <DatePicker
          id={`${id}-date`}
          aria-labelledby={`${id}-date-label`}
          aria-describedby={`${id}-date-hint`}
          value={date}
          onValueChange={setDate}
          disabledDates={{ dayOfWeek: [0, 6] }}
          defaultMonth={exampleMonth}
        />
        <FieldDescription id={`${id}-date-hint`}>Appointments are available on weekdays.</FieldDescription>
      </Field>
    </div>
  )
}

Range

Show a selected range in the trigger and the open calendar. Range selection keeps the popup open so both endpoints can change.

"use client"

import * as React from "react"
import type { DateRange } from "react-day-picker"

import { DatePicker } from "@/components/ui/date-picker"
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

const exampleMonth = new Date(2026, 9, 1)

export function DatePickerRange() {
  const id = React.useId()
  const [date, setDate] = React.useState<Date | undefined>()
  const [range, setRange] = React.useState<DateRange | undefined>()
  const [start, setStart] = React.useState<Date | undefined>()
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel id={`${id}-range-label`} htmlFor={`${id}-range`}>
          Report period
        </FieldLabel>
        <DatePicker
          mode="range"
          id={`${id}-range`}
          aria-labelledby={`${id}-range-label`}
          aria-describedby={`${id}-range-hint`}
          value={range}
          onValueChange={setRange}
          placeholder="Pick a start and end date"
          defaultMonth={exampleMonth}
        />
        <FieldDescription id={`${id}-range-hint`}>Choose the first and last day to include.</FieldDescription>
      </Field>
    </div>
  )
}

Invalid

Associate validation feedback with the trigger. The error replaces the hint and the trigger is marked invalid.

"use client"

import * as React from "react"

import { DatePicker } from "@/components/ui/date-picker"
import { Field, FieldError, FieldLabel } from "@/components/ui/field"

const exampleMonth = new Date(2026, 9, 1)

export function DatePickerInvalid() {
  const id = React.useId()
  const [date, setDate] = React.useState<Date | undefined>()
  
  const [start, setStart] = React.useState<Date | undefined>()
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel id={`${id}-start-label`} htmlFor={`${id}-start`}>
          Contract start
        </FieldLabel>
        <DatePicker
          id={`${id}-start`}
          aria-labelledby={`${id}-start-label`}
          aria-describedby={`${id}-start-error`}
          aria-invalid
          value={start}
          onValueChange={setStart}
          defaultMonth={exampleMonth}
        />
        <FieldError id={`${id}-start-error`}>Choose the day the contract starts.</FieldError>
      </Field>
    </div>
  )
}

Disabled with reason

Show a fixed date on a disabled trigger and explain why it cannot change. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { DatePicker } from "@/components/ui/date-picker"
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

export function DatePickerDisabledWithReason() {
  const id = React.useId()
  const [date, setDate] = React.useState<Date | undefined>()
  
  
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel id={`${id}-renewal-label`} htmlFor={`${id}-renewal`}>
          Renewal date
        </FieldLabel>
        <DatePicker
          id={`${id}-renewal`}
          aria-labelledby={`${id}-renewal-label`}
          aria-describedby={`${id}-renewal-hint`}
          defaultValue={new Date(2027, 0, 15)}
          disabled
        />
        <FieldDescription id={`${id}-renewal-hint`}>
          Set by your plan. It changes when you switch plans.
        </FieldDescription>
      </Field>
    </div>
  )
}

Delivery window

Bound the navigable months and disable days outside the delivery window. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { DatePicker } from "@/components/ui/date-picker"
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

const exampleMonth = new Date(2026, 9, 1)

export function DatePickerDeliveryWindow() {
  const id = React.useId()
  const [date, setDate] = React.useState<Date | undefined>()
  
  
  const [delivery, setDelivery] = React.useState<Date | undefined>()
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel id={`${id}-delivery-label`} htmlFor={`${id}-delivery`}>
          Delivery date
        </FieldLabel>
        <DatePicker
          id={`${id}-delivery`}
          aria-labelledby={`${id}-delivery-label`}
          aria-describedby={`${id}-delivery-hint`}
          value={delivery}
          onValueChange={setDelivery}
          defaultMonth={exampleMonth}
          startMonth={exampleMonth}
          endMonth={new Date(2026, 10, 1)}
          disabledDates={[{ before: new Date(2026, 9, 5) }, { dayOfWeek: [0] }]}
        />
        <FieldDescription id={`${id}-delivery-hint`}>
          We deliver Monday to Saturday, from October 5 to the end of November.
        </FieldDescription>
      </Field>
    </div>
  )
}

Custom format

Format the trigger text with a pattern that includes the weekday. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { DatePicker } from "@/components/ui/date-picker"
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

export function DatePickerCustomFormat() {
  const id = React.useId()
  const [date, setDate] = React.useState<Date | undefined>()
  
  
  
  const [due, setDue] = React.useState<Date | undefined>(new Date(2026, 9, 30))

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel id={`${id}-due-label`} htmlFor={`${id}-due`}>
          Due date
        </FieldLabel>
        <DatePicker
          id={`${id}-due`}
          aria-labelledby={`${id}-due-label`}
          aria-describedby={`${id}-due-hint`}
          value={due}
          onValueChange={setDue}
          dateFormat="EEE, MMM d, yyyy"
        />
        <FieldDescription id={`${id}-due-hint`}>
          Payment is due by the end of this day.
        </FieldDescription>
      </Field>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

DatePicker

Choose a date or a date range from a calendar in a popup. Composes Button, Popover and Calendar; the trigger forwards id, aria-describedby and aria-invalid so it works inside Field and FormControl. The trigger's accessible name includes the selected value.

DatePicker props
PropTypeDefaultDescription
idstring | undefined—Trigger id. Use it with a label htmlFor, or let FormControl supply it.
placeholderstring | undefined—Text shown when no date is selected. It is not the control's accessible name.
disabledboolean | undefined—Prevents opening the calendar. The trigger leaves the Tab order.
disabledDatesMatcher | Matcher[] | undefined—Dates that cannot be chosen, using React DayPicker matchers such as { before: today } or { dayOfWeek: [0, 6] }.
localeimport("react-day-picker").DayPickerLocale | undefined—Locale from react-day-picker/locale used for the trigger text, weekday names and day labels. Defaults to English (US).
dateFormatstring | undefined—date-fns format pattern for the trigger text. Defaults to a localized long date ("PPP") for one date and a medium date ("PP") for ranges.
defaultMonthDate | undefined—Month shown when the calendar opens with no selection.
startMonthDate | undefined—Earliest navigable month.
endMonthDate | undefined—Latest navigable month.
numberOfMonthsnumber | undefined—Months shown side by side. Defaults to 1; keep 1 where the popup must fit a phone width.
calendarLabelstring | undefined—Accessible name for the calendar popup.
align"center" | "start" | "end" | undefined—Popup alignment relative to the trigger.
classNamestring | undefined—Additional classes for the trigger. Preserve focus visibility, contrast and content reflow when adapting styles.
aria-labelstring | undefined—Names the trigger directly. Prefer a visible label with aria-labelledby or htmlFor.
aria-labelledbystring | undefined—Id of a visible label. The selected value is appended to the trigger's name.
aria-describedbystring | undefined—Ids of hint or error text, as supplied by Field wiring or FormControl.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Marks the trigger invalid; pair it with an associated error message.
onBlurReact.FocusEventHandler<HTMLButtonElement> | undefined—Called when focus leaves the trigger, for form libraries that track touched state.
mode"single" | "range" | undefined—Choose one date. The popup closes after a selection. Choose a start and end date. The popup stays open until Escape, an outside click or a focus move.
valueDate | DateRange | undefined—Controlled selected date. Pair with onValueChange. Controlled selected range. Pair with onValueChange.
defaultValueDate | DateRange | undefined—Initial date for uncontrolled usage. Initial range for uncontrolled usage.
onValueChange((value: Date | undefined) => void) | ((value: DateRange | undefined) => void) | undefined—Called with the chosen date, or undefined when the selected day is chosen again. Called with the updated range. The first click sets from and to to the same day; the next click extends it.
Inherited props (1)
DatePicker inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLButtonElement> | undefined—Ref to the trigger button, so form libraries can focus an invalid field.

Accessibility & usage

From registry/ui/date-picker.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Dates where seeing the week or month helps: appointments, deadlines, delivery or report periods.
  • A start and end date in one control with mode="range".
  • Inside Field or FormControl, where the trigger needs the label, hint or error association and the invalid state.

When not to use

  • Dates people know and type faster, such as a date of birth; use a text input with a documented format.
  • Time of day, time zones or durations; the picker selects calendar days only.
  • An always-visible calendar that is the main content; use Calendar directly.

Anatomy

DatePicker
One component: a Button trigger, a Popover and a Calendar. Takes mode, value or defaultValue, onValueChange, disabledDates, locale, dateFormat, defaultMonth, startMonth, endMonth, numberOfMonths, calendarLabel, align, placeholder, disabled, id and ref.
Trigger
A neutral stroke Button with a calendar icon and the formatted value or placeholder. Forwards id, aria-describedby, aria-invalid and onBlur; its accessible name combines the label and the value.
Popup
A Popover named by calendarLabel ('Choose a date' by default) that holds the Calendar.

Keyboard & interaction

  • Enter, Space or a click on the trigger opens the popup and moves focus to the selected day, today or the first available day.
  • Calendar keys apply inside the popup (arrows, Page Up and Page Down, Home and End).
  • Single mode closes after a choice and returns focus to the trigger; choosing the selected day again clears it.
  • Range mode stays open: the first choice sets the start, the next one the end; Escape, an outside click or moving focus closes it.
  • Disabled triggers leave the Tab order; disabled dates cannot be selected.

Responsive behavior

  • The trigger is full width with a 40 CSS px minimum height; long formatted values wrap instead of truncating.
  • The popup is never wider than the viewport minus 2rem; keep one month on phones.
  • Align the popup with align when the trigger sits at the end of a row.

Content guidelines

  • Label names the date ('Appointment date'); the placeholder prompts ('Pick a date') and is not the name.
  • Hint states constraints before people open the calendar ('Appointments are available on weekdays').
  • Error says what to choose ('Choose the day the contract starts').
  • dateFormat: prefer an unambiguous format with the month name; include the weekday when it matters.

Alternatives

  • Calendar — An inline calendar without a trigger.
  • Input — Typed dates people already know.
  • Native select — Coarse choices such as a month or a year.

Resources