Date Picker
A button that opens a calendar in a popover, so people can fill a date field in a form.
Installation
Date Picker is a composition, not a component of its own: there is no date-picker file in components/ui and no registry item. It is made from Popover, Calendar and Button. Add the components it uses:
pnpm dlx shadcn@latest add @silkware/popover @silkware/calendar @silkware/button @silkware/fieldDates are objects from @internationalized/date. The examples on this page avoid importing it, so they need nothing more. If you create dates yourself (parseDate, today) or set minValue, maxValue or defaultValue, add it to your own dependencies:
pnpm add @internationalized/dateUsage
import { CalendarIcon } from "lucide-react"import type { DateValue } from "react-aria-components"
import { Button } from "@/components/ui/button"import { Calendar } from "@/components/ui/calendar"import { Popover, PopoverTrigger } from "@/components/ui/popover"const [date, setDate] = React.useState<DateValue | null>(null)
<PopoverTrigger> <Button variant="outline" id="delivery-date"> <CalendarIcon data-icon="inline-start" /> {date ? formatDate(date) : <span>Pick a date</span>} </Button> <Popover className="w-auto p-0" placement="bottom start"> <Calendar aria-label="Delivery date" value={date} onChange={setDate} /> </Popover></PopoverTrigger>The structure is a PopoverTrigger holding a Button and a Popover that holds a Calendar. The Popover is w-auto p-0 so the calendar sets its own size. Pair the button with a FieldLabel whose htmlFor matches the button's id, so the label names the button.
The state holds a date object. Format it for display with date.toDate("UTC").toLocaleDateString(undefined, { dateStyle: "long", timeZone: "UTC" }). Using UTC on both sides keeps the day the same in every time zone. The popover stays open after a pick unless you control it with isOpen and onOpenChange and close it from onChange.
Examples
Range
Swap Calendar for RangeCalendar to pick a start and an end. Close the popover from onChange once both dates are set if you want it to close on its own. Intl.DateTimeFormat.formatRange writes the two dates as one range.
Month and year dropdowns
For a date that can be far from today, set captionLayout="dropdown" on the calendar and close the popover as soon as a day is chosen.
With time
The calendar picks a day only. Put a time Input next to the picker for a date and a time, each with its own label.
Unavailable dates
isDateUnavailable on the calendar marks dates that cannot be chosen. Say why in a FieldDescription.
Pickups are not made on Sundays.
Invalid
Set data-invalid on the Field to colour the label, add border-destructive to the button, and show the reason in a FieldError.
Disabled
isDisabled on the Button stops the popover from opening.
A typed date field
The official recipe also has a version with a text input next to the calendar button. It needs parseDate and fromDate from @internationalized/date to turn typed text into a date, so it is not shown here. Build it from InputGroup, InputGroupButton and the same Popover and Calendar.
Accessibility
| Key | Action |
|---|---|
| Enter | Opens the popover from the button, and selects the focused day in the calendar. The popover stays open after a pick unless you close it. |
| Space | Opens the popover from the button, and selects the focused day in the calendar. The popover stays open after a pick unless you close it. |
| Tab | Moves focus from the popover to the previous and next month buttons, then to the day grid. |
| Escape | Closes the popover and returns focus to the button. |
| ArrowLeft | Moves focus to the previous day. |
| ArrowRight | Moves focus to the next day. |
| PageUp | Moves focus to the same day in the previous month. |
| PageDown | Moves focus to the same day in the next month. |
All the other calendar keys are listed on the Calendar page.
React Aria provides:
- Popover behaviour from
PopoverTrigger: the button reportsaria-expandedandaria-haspopup="dialog", focus moves into the popover when it opens, onto the dialog itself, so Tab then reaches the month buttons and the day grid. Focus returns to the button when it closes. - The keyboard model, labelled grid and localised month and weekday names of the Calendar.
- Dismissal on Escape or a click outside.
You provide:
- A visible
FieldLabellinked to the button withhtmlForandid, and anaria-labelon theCalendar. - The chosen date as text on the button. The placeholder alone does not say what is chosen.
- A
FieldErrorthat says what to fix, and aFieldDescriptionfor rules such as unavailable days. - A text field alternative when people may already know the exact date, because a calendar is slow for that.
Guidelines
When to use
- To fill a date in a form: a delivery date, a pickup date, an audit date.
- To fill a date range, such as a production window or a reporting period.
- When people benefit from seeing the weekday and the neighbouring days.
When not to use
- To show a calendar always open on the page. Use a Calendar directly.
- When the date is known to the person and typing is faster, such as a date of birth. Use an Input, or the dropdown layout.
- For a date more than a few years away without the dropdowns. Use
captionLayout="dropdown". - To choose among a few fixed options, such as "Today" and "Tomorrow". Use a Radio Group or a Select.
Content
- Label the field with what the date means: "Delivery date", not "Date".
- Use "Pick a date" as the placeholder, or "Pick a date range" for a range.
- Show the chosen date in a long, unambiguous form such as "14 December 2026", not in a numeric format that reads differently by region.
- Say in a description why some dates cannot be chosen.
Label
Show a visible label above the picker.
Don’t leave the placeholder as the only text. Once a date is chosen, nothing says what it is for.
API reference
Date Picker has no exported parts of its own. It is made of the parts below; follow their pages for every prop.
PopoverTrigger
Wraps the button and the popover and holds the open state. It is the React Aria DialogTrigger. Control it with isOpen and onOpenChange. See Popover.
| Prop | Type | Default | Description |
|---|---|---|---|
isOpen? | boolean | None | Whether the popover is open, for a controlled picker. |
defaultOpen? | boolean | None | Whether the popover starts open. |
onOpenChange? | (isOpen: boolean) => void | None | Called when the popover opens or closes. |
Button
The control that opens the popover and shows the chosen date. Use variant="outline" and justify-start font-normal, and dim the placeholder with data-[empty=true]:text-muted-foreground. See Button.
Popover
The surface that holds the calendar. Use className="w-auto p-0" and placement="bottom start" so it lines up with the button. See Popover.
Calendar and RangeCalendar
The date grid. Give it value, onChange and an aria-label. See Calendar for minValue, maxValue, isDateUnavailable, captionLayout and numberOfMonths.