DatePicker

Inputs

Stablev1.0.0

Accessible date picker with a popover calendar for selecting a single date.

Preview

Installation

npx @component-labs/cli add date-picker

This will:
- Install required dependencies (@ariakit/react, class-variance-authority, lucide-react)
- Copy the DatePicker component to your project
- Add utility functions (cn helper)

Make sure you've initialized Component Labs first:
```bash
npx @component-labs/cli init
```

Usage

import { DatePicker } from "@component-labs/ui";

<DatePicker placeholder="Pick a date" />

Props

NameTypeDefaultDescription
valueDate-Controlled selected date
defaultValueDate-Default selected date (uncontrolled)
onChange(date: Date) => void-Called when a date is selected
placeholderstring"Pick a date…"Placeholder text when no date is selected
disabledboolean-Whether the picker is disabled
labelReactNode-Label displayed above the trigger
errorstring-Error message — switches trigger to error variant
classNamestring-Additional CSS classes for the wrapper

Examples

Basic

Simple date picker

<DatePicker placeholder="Pick a date" />

With Label

Date picker with a label

<DatePicker label="Date of birth" placeholder="Select date" />

With Default Value

Pre-selected date

<DatePicker defaultValue={new Date(2025, 0, 15)} />

Controlled

Controlled date picker

const [date, setDate] = useState<Date>();

<DatePicker
  value={date}
  onChange={setDate}
  label="Appointment date"
/>
{date && <p>Selected: {date.toDateString()}</p>}

With Error

Date picker with validation error

<DatePicker
  label="Required field"
  error="Please select a date"
/>

Disabled

Disabled date picker

<DatePicker
  disabled
  defaultValue={new Date()}
  label="Disabled"
/>

Performance

Bundle Size

~5KB gzipped

Minified and gzipped

Dependencies

  • @ariakit/react
  • class-variance-authority
  • clsx
  • tailwind-merge
  • lucide-react

Accessibility

  • Built on Ariakit Popover for accessible disclosure pattern
  • Keyboard navigation: Enter/Space opens calendar, Escape closes
  • ARIA attributes automatically applied to trigger and popover
  • Today highlighted visually for orientation
  • Disabled state prevents interaction and updates ARIA