Skip to content
synccn

Date Picker

Field that opens a calendar, for one date or a range, with presets.

Installation

$ pnpm dlx shadcn@latest add @synccn/date-picker

First time in this project? Connect synccn with one command.

Usage

import { DatePicker } from "@/components/ui/date-picker";<DatePicker mode="range" value={range} onChange={setRange} />

API reference

Generated from the component's TypeScript types, so it always matches the code.

DatePicker

Field that opens a Calendar. mode "single" -> Date, mode "range" -> { from, to }.

  • mode
    "single" | "range"

    Default "single"

    One date or a range.

  • value
    Date | null | DateRange

    Controlled value.

  • onChange
    ((value: Date | null) => void) | ((value: DateRange) => void)

    Called with the new Date or { from, to }.

  • presets
    ({ label: string; value: () => Date }[]) | ({ label: string; value: () => DateRange }[])

    Quick picks shown beside the calendar.

  • placeholder
    string

    Default "Pick a date"

    Shown when empty.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Components

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseAutoSide (flips to the side with room), useClickOutside (closes on an outside click), useEscape (closes on Escape), usePresence (animates in and out)

npm packages

Keyboard

  • EnterorSpaceOpen the calendar
  • TabMove through days and presets
  • EscClose

Accessibility

  • Days are buttons inside a grid with column headers; the selected day sets aria-selected.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: button
  • ARIA attributes: aria-expanded, aria-label
  • Closes with Escape
  • Closes when you click or tap outside
  • Flips to whichever side has room, so it stays on screen
  • Shows a visible focus ring for keyboard users