Search documentation

Search pages, components, blocks, styles and colours.

Get started
Skip to content

Date Picker

PreviousNext

A date field that opens a calendar, with an optional time wheel, a month or year granularity, and Calendar compositions for ranges and presets.

Installation

bunx --bun fabricator-ui@latest add date-picker

Usage

import { DatePicker } from "@/components/ui/date-picker"
import { DensityScope } from "@/components/ui/density"
import {
  Field,
  FieldDescription,
  FieldError,
  FieldLabel,
} from "@/components/ui/field"
import { Text } from "@/components/ui/text"
<DatePicker aria-label="Due date" placeholder="Pick or type a date" />

Examples

date-picker-example.tsx
import * as React from "react"
 
import { DatePicker } from "@/components/ui/date-picker"
import { DensityScope } from "@/components/ui/density"
import {
  Field,
  FieldDescription,
  FieldError,
  FieldLabel,
} from "@/components/ui/field"
import { Text } from "@/components/ui/text"
 
function DatePickerExample() {
  const [date, setDate] = React.useState<Date | undefined>(
    new Date(2026, 10, 12)
  )
  return (
    <ExampleWrapper fit>
      <Example title="Default">
        <DatePicker aria-label="Due date" placeholder="Pick or type a date" />
      </Example>
      <Example title="In a field">
        <Field>
          <FieldLabel>Start date</FieldLabel>
          <DatePicker placeholder="Nov 12, 2026" />
          <FieldDescription>
            Type a date, or press the calendar to pick one.
          </FieldDescription>
        </Field>
      </Example>
      <Example title="Controlled">
        <DatePicker
          aria-label="Publish on"
          value={date}
          onValueChange={setDate}
        />
        <Text className="text-muted-foreground tabular-nums">
          {date
            ? date.toLocaleDateString("en-US", { dateStyle: "full" })
            : "No date"}
        </Text>
      </Example>
      <Example title="Month">
        <Field>
          <FieldLabel>Card expiry</FieldLabel>
          <DatePicker granularity="month" placeholder="Mar 2028" />
          <FieldDescription>
            Type 3/2028 or Mar 2028, or press the calendar to pick one.
          </FieldDescription>
        </Field>
      </Example>
      <Example title="Year">
        <DatePicker
          aria-label="Graduation year"
          granularity="year"
          minDate={new Date(1980, 0, 1)}
          maxDate={new Date(2030, 0, 1)}
          defaultValue={new Date(2024, 0, 1)}
        />
      </Example>
      <Example title="Format">
        <DatePicker
          aria-label="Date of birth"
          format="dd/MM/yyyy"
          placeholder="dd/mm/yyyy"
          defaultValue={new Date(1994, 2, 18)}
        />
      </Example>
      <Example title="Minimum and maximum">
        <DatePicker
          aria-label="Delivery date"
          minDate={new Date(2026, 10, 9)}
          maxDate={new Date(2026, 11, 18)}
          defaultValue={new Date(2026, 10, 16)}
        />
      </Example>
      <Example title="Invalid">
        <Field data-invalid>
          <FieldLabel>Renewal date</FieldLabel>
          <DatePicker aria-invalid defaultValue={new Date(2026, 0, 4)} />
          <FieldError>Pick a date after today.</FieldError>
        </Field>
      </Example>
      <Example title="Disabled">
        <DatePicker
          aria-label="Created"
          disabled
          defaultValue={new Date(2026, 9, 2)}
        />
      </Example>
      <Example title="Sizes">
        <DensityScope density="compact">
          <DatePicker
            aria-label="Compact date"
            defaultValue={new Date(2026, 10, 12)}
          />
        </DensityScope>
        <DatePicker aria-label="Date" defaultValue={new Date(2026, 10, 12)} />
        <DensityScope density="spacious">
          <DatePicker
            aria-label="Spacious date"
            defaultValue={new Date(2026, 10, 12)}
          />
        </DensityScope>
      </Example>
    </ExampleWrapper>
  )
}
 
export { DatePickerExample }

API reference

Props it adds to what it wraps: "aria-invalid", calendarLabel, defaultValue, disabled, format, granularity, locale, maxDate, minDate, name, onValueChange, value.

Accessibility

Text is read as it appears. Give a control with no text an accessibilityLabel.