Date Picker

Single date and date range in a popover, with presets and a clear button.

Category
Forms
Access
Free with an account
Source
244 lines · one file

When to use it

Use DatePicker for one date, such as a due date or a birthday, and DateRangePicker for reports and filters that need a start and an end. Presets like "Last 7 days" save most people from touching the calendar at all. disabledDays takes react-day-picker matchers, such as no past dates or no weekends.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Liro's Date Picker for this.
Install it: npx shadcn@latest add @liro/date-picker
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/date-picker.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Free components install through the @liro registry with your CLI token: see the Namespaced tab.

Usage

components/report-filters.tsx
"use client";

import * as React from "react";
import { DatePicker, DateRangePicker, type DateRange } from "@/components/ui/date-picker";

const daysAgo = (n: number) => new Date(Date.now() - n * 86_400_000);

export function ReportFilters() {
  const [due, setDue] = React.useState<Date>();
  const [range, setRange] = React.useState<DateRange | undefined>();

  return (
    <div className="flex gap-3">
      <DatePicker value={due} onValueChange={setDue} placeholder="Due date" disabledDays={{ before: new Date() }} clearable />
      <DateRangePicker
        value={range}
        onValueChange={setRange}
        presets={[
          { label: "Last 7 days", range: () => ({ from: daysAgo(7), to: new Date() }) },
          { label: "Last 30 days", range: () => ({ from: daysAgo(30), to: new Date() }) },
        ]}
      />
    </div>
  );
}

API reference

“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

TypeNotes
valueDate No–
defaultValueDate No–
onValueChange(date: Date | undefined) => void No–

Dependencies

npm packages

clsxdate-fnslucide-reactreact-day-pickertailwind-merge

Liro foundations, installed alongside it

liro-themecalendarfieldpopover

Accessibility

  • Keyboard reachable throughout, in visual order
  • Focus trapped in overlays, Escape closes them
  • Focus returns to whatever opened it
  • Live regions announce what changed, not that something did
  • Honours prefers-reduced-motion

Responsive behavior

  • Sizes to its container, not the viewport
  • Usable from 320px up
  • Pointer-based interaction, so trackpad and touch both work
  • No hover-only affordances

Used in a screenAll screens