Skip to content

Now in the official shadcn registry directory.

Start free

Date Picker

A date field that opens the ai2 Calendar in a Popover. Controlled or uncontrolled via value, defaultValue and onValueChange, formatted with date-fns.

form
A free styled version is available

Installation

Run the following command

npx shadcn@latest add @ai2/date-picker

date-fns, the ai2 Button, Calendar and Popover, the @ai2/tokens theme and the component file are installed together.

Usage

TS
import { DatePicker } from "@/components/ui/date-picker"

<DatePicker placeholder="Select a date" />

Control it with value and onValueChange, or drop it in with an optional defaultValue and let it manage its own selection.

Examples

Uncontrolled default value

Pass defaultValue for an initial date and let the component track the selection on its own, no state wiring required.

Placeholder

Disabled

Custom width

The trigger defaults to 224px wide. Pass a width utility through className to match a form column.

Props

PropTypeDefaultDescription
valueDateundefinedThe controlled selected date. Pair it with onValueChange to drive the picker from your own state.
defaultValueDateundefinedThe initial date for uncontrolled use. The component then tracks selection internally.
onValueChange(date: Date | undefined) => voidundefinedFires with the newly selected date, or undefined when the selection is cleared. The popover closes after a pick.
placeholderstring"Pick a date"Muted text shown on the trigger when no date is selected.
localeLocaleundefinedA date-fns locale object. It localizes the trigger label and is forwarded to the inner Calendar, so weekday and month names follow it too.
formatStrstring"PPP"The date-fns format pattern used for the trigger label when a date is selected.
calendarPropsComponentProps<typeof Calendar>undefinedExtra props forwarded to the inner Calendar, such as disabled matchers, startMonth or captionLayout. mode, selected and onSelect stay managed by the picker.
disabledbooleanfalseDisable the trigger so the popover can no longer be opened.
classNamestringundefinedClasses for the trigger Button. The default is a 224px wide, left-aligned field; override the width or other styles here.

ai2 Date Picker: a calendar-in-popover date field for React

The ai2 Date Picker is a shadcn-compatible date field for React that opens the ai2 Calendar inside a Popover. Click the trigger, pick a day, and the selected date shows on the button formatted with date-fns. It works controlled through value and onValueChange, or uncontrolled through defaultValue.

Because it ships through the shadcn registry format, you install it with one CLI command, an MCP agent, or a copy-paste, and the source lands in your own project. You own the file; there is no runtime dependency on ai2 itself. The live example above is the exact component you get.

What is the ai2 Date Picker?

It composes three ai2 components: an outline Button trigger with a lucide calendar icon, a Popover for the floating panel, and the ai2 Calendar in single mode for the grid. The whole field is exported as one DatePicker component.

It keeps a small internal state so it works with no wiring at all, while still accepting value and onValueChange for full control. The trigger formats the date with the date-fns PPP pattern, for example July 9th, 2026, and shows the placeholder in muted text when nothing is selected. Selecting a day closes the popover automatically.

Why use it

  • Controlled or uncontrolled: Drive it from state with value and onValueChange, or drop it in with an optional defaultValue and let it manage its own selection.
  • One import, three parts wired: The Button trigger, Popover and Calendar are already composed and connected, so you get a complete date field from a single component.
  • Readable formatting: The selected date renders through the date-fns PPP pattern, a long, human-friendly format, with no manual toLocaleDateString wiring.
  • Consistent with your controls: The trigger is an outline ai2 Button and the panel is the ai2 Calendar, so the field matches your inputs and buttons in both light and dark mode.
  • Agent-readable metadata: The registry item describes its props and composition in plain words, so an MCP agent can find, inspect and install it without guessing.

Features

  • shadcn registry install: One command adds the component, date-fns, the ai2 Button, Calendar and Popover dependencies and the @ai2/tokens theme to your project.
  • Popover-mounted calendar: The Calendar renders inside a Popover aligned to the trigger, so it floats above the layout and never gets clipped by overflow containers.
  • Auto-close on select: Picking a day updates the value and closes the popover in one motion, matching how users expect a date field to behave.
  • Placeholder and empty state: A data-empty attribute and muted text mark the unselected state, so the trigger reads as a prompt until a date is chosen.
  • Width via className: The trigger defaults to a 224px left-aligned field; pass a className to widen it, match a form column or restyle it entirely.
  • Disabled support: The disabled prop turns off the trigger so the popover cannot open, for read-only forms or closed booking windows.

Production tips

  • Lift state when you need the value: For forms, control the picker with value and onValueChange so the selected Date lives in your state and can be validated or submitted.
  • Match your form column width: The default trigger is 224px wide. Pass className="w-full" or a fixed width so the field lines up with the inputs around it.
  • Reach for Calendar directly for ranges: The Date Picker is single-date only. For a start and end range, use the ai2 Calendar in range mode inside your own Popover.
  • Localize the format if needed: Pass a date-fns locale to render the trigger label and the calendar in another language, and use formatStr to change the date-fns pattern away from the PPP default.
  • Set a helpful placeholder: Replace the default Pick a date with the field's purpose, for example Choose a check-in day, so the empty state guides the user.

Works with the rest of ai2

The Date Picker is built from the ai2 Calendar, the ai2 Popover and an outline ai2 Button, so it inherits their focus rings, animations and token styling for free.

Pair it with a ai2 Label and ai2 Field to build a labelled form row, and reach for the Calendar on its own when you need multiple or range selection. Everything shares one token source, so combinations stay visually consistent in both modes.

FAQs

Get new components in your inbox

Component drops, new themes and release notes. No spam, and you can unsubscribe from any email.

© 2026 ai2 design system · MIT licensed · Built with its own components