shadcn.io is an independent project built on shadcn/ui
Components
Free
Date Picker for UI SDK
A button or typed field that opens a month in a popover, for one date or a range, for React on UI SDK, with year menus and a time field.
On this page9 sections
A date picker is a form field for a date: a button, or a text input, that opens a month in a popover and closes once a day is picked, leaving the date written in the field. Use it when the date is one entry among others, as in a booking form or a profile.
When choosing the date is the main task and the month should stay in view, use a Calendar. For a date typed segment by segment with no popover at all, use a Date Input.
Installation
Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
The trigger is a button with aria-haspopup="dialog" that reports aria-expanded, and opening moves focus into the dialog's grid, onto the selected day, or today when nothing is picked. Each day is named by its full date, weekday included. On its own the trigger is named Choose date, followed by the picked date once there is one. Pass the field label's id to DatePickerTrigger as aria-labelledby, as the Basic demo does, and the label and what DatePickerValue shows name it instead. Inside a Field, the FieldLabel names it the same way with no id to pass, and pressing the label opens the picker. Picking a day or pressing Escape sends focus back to the trigger.
KeyAction
Enter
On the trigger, opens the calendar. On a day, selects it and closes the calendar, or in a range waits for the second day. In the input, commits the typed date.
Space
On the trigger, opens the calendar. On a day, selects it as a click does.
Arrow Left
Moves focus to the previous day, into the previous week or month when it has to.
Arrow Right
Moves focus to the next day, into the next week or month when it has to.
Arrow Up
Moves focus to the same day of the week in the previous week.
Arrow Down
Moves focus to the same day of the week in the next week.
Home
Moves focus to the first day of the week.
End
Moves focus to the last day of the week.
Page Up
Moves focus to the same day of the month in the previous month.
Page Down
Moves focus to the same day of the month in the next month.
Shift+Page Up
Moves focus to the same day in the previous year.
Shift+Page Down
Moves focus to the same day in the next year.
Alt+Arrow Down
In the input, opens the calendar on the typed date's month.
EscEscape
In a range with only its start picked, cancels that pick. Otherwise closes the calendar without changing the date.
The month and year views, a DatePickerView with view set to month or year, are grids too, with one tab stop. The arrow keys move a month or a year at a time, mirrored right to left, Home and End go to the first and last month of the year or year of the decade, and PageUp and PageDown move a year or a decade. Enter or Space picks the focused one.
Demos
Basic
A button under a Date label that reads Pick a date until a day is chosen, then shows it as month, day and year in digits. The popover holds one month with previous and next buttons, and the click that picks a day closes it. Use this shape for a date close to today in a form, such as a delivery or a start date.
Range
Two months open side by side, with January 20 of this year to 20 days later already selected, so the button shows both dates with a hyphen between them. The next click starts a new range, and the one after it ends the range and closes the popover. Opening it puts keyboard focus on January 20, the start of the range.
Disabled dates
Weekends, the 3rd through the 7th of this month and the 22nd can't be picked: isDateUnavailable returns true for each, and they stay in the grid with a line through the number. The button shows the picked date in long form, written by the demo itself. Add min set to today when the past should close as well.
DOB
A date of birth field with month and year menus between the arrows. With no min or max, the year menu lists ten years either side of the year shown, so going decades back takes a few picks. open and value are held in state, and picking a day closes the popover. For a real birth date, set min and max, and the year menu runs between their years.
Input
A text field under a Subscription Date label, starting at June 1, 2025, with a calendar button at its end. People type digits in the locale's order, 06/01/2025 in US English, and Enter or leaving the field commits the date. Emptied, it stays blank unless you pass placeholder. The label points at an id passed to DatePickerInput, since the picker otherwise gives the input an id of its own.
Time
A Date button and a Time field side by side. The time is a DatePickerTimer, a native time input with seconds that starts at 10:30:00, and the date popover has month and year menus. The two values stay separate until you join them when you save, as for an appointment that needs a day and an hour.
Natural language
A text field that starts with In 2 days filled in and understands today, tomorrow, next week and in a number of days, plus any string Date.parse reads. A phrase it understands sets the date as you type, and the line underneath spells it out. ArrowDown or the calendar button opens the month. The parsing is the demo's own code, in English, so write your own for other phrases.
RTL
The picker in Arabic, inside a LocaleProvider with the ar locale, so the placeholder, the weekday names and the grid read right to left, and ArrowLeft moves to the next day. The provider wraps the picker in an element with lang and dir set, and the popover, which renders at the end of the page, still takes both from it. Use it to check a form in Arabic or Hebrew.
FAQ
How do I get the selected date from the Date Picker in React?
Read it in onValueChange, which gets details.value, an array of DateValue objects even for one date, and details.valueAsString, the same dates formatted for the locale. On UI SDK a DateValue is this component's own object, with no date library behind it, and parseDate from the same file makes one. Call toString() on it for an ISO string such as 2026-11-11, or toDate() for a JavaScript Date.
How do I select a date range with the Date Picker?
Set selectionMode to range. The first click sets the start, the second sets the end and closes the popover, and the value holds the two dates in order. Set numOfMonths to 2 and put DatePickerTableNextMonth in a second table to show two months side by side, as the Range demo does.
Give DatePickerValue a separator, such as a hyphen with spaces, for the text on the button. For separate dates instead, set selectionMode to multiple, and the popover stays open while people click.
How do I disable past dates or weekends in the Date Picker?
Set min to today, made with parseDate(new Date()) from this component, and the days before it fade, can't be picked, and Previous stops at that month. max does the same for days after a date.
For weekends, holidays or booked days, pass isDateUnavailable, which gets each date and the locale and returns true for a day to block, as the Disabled dates demo does. Blocked days stay in the grid, and Enter does nothing on them.
How do I make a birthday Date Picker that jumps to a year?
Put DatePickerMonthSelect and DatePickerYearSelect between the arrows, as the DOB demo does, so 1984 is one choice in a list instead of hundreds of clicks back. Without min or max, the year list holds ten years either side of the year shown.
Set max to today, which disables the future days and ends the year list at this year, and min to the earliest date that makes sense for your form, whose year then opens the list.
Can users type a date in the Date Picker instead of clicking?
Yes, use DatePickerInput in place of the trigger button, as the Input demo does, and the calendar opens from the button at its end. The field takes digits and the separator in the locale's order, such as 06/01/2025 in US English, and commits the date on Enter or when it loses focus. Give it an id for the field's label to point at, since the picker sets an id of its own.
For phrases such as tomorrow or in 3 days, the Natural language demo parses the text itself and keeps a calendar for clicking.
How do I pick a date and a time with the Date Picker?
Put a DatePickerTimer next to the picker, as the Time demo does. It is a native time input with seconds, and its value stays apart from the date, so join the two when you save, from the date's year, month and day and the time's hours and minutes.
For a date and time typed into one field, segment by segment, use a Date Input with granularity set to minute.
How do I change the Date Picker language and the first day of the week?
Set locale, such as fr-FR or de-DE, and the month and weekday names, the date on the button and the input's format all follow it. Set startOfWeek to a number from 0 for Sunday to 6 for Saturday to choose the first column, or leave it out and the locale decides.
The direction doesn't follow locale. For Arabic or Hebrew, wrap the picker in a LocaleProvider with that locale, which sets the language and the direction on an element around it, as the RTL demo does. The popover renders at the end of the page but takes the direction from that element, so the grid runs right to left, with ArrowLeft moving to the next day.
Why does the Date Picker open above the field?
This component passes positioning with placement set to top unless you pass your own, so the popover opens upward and flips below only when there isn't room above. Pass positioning with placement set to bottom-start to open it under the field, lined up with its start edge.
The same object takes gutter, the gap between the field and the popover in pixels, which is 8 by default.
API Reference
DatePicker
PropType
open?boolean
Whether it's open. Pair with onOpenChange to control it.
defaultOpen?boolean
Whether it starts open, when you don't control open.
onOpenChange?(details: { open: boolean }) → void
Called when it opens or closes.
Type
(details: { open: boolean }) → void
Parameters
details – { open: boolean }
Returns
void
value?DateValue[]
The value. Pair with onValueChange to control it.
defaultValue?DateValue[]
The value it starts with, when you don't control value.
Called when the user changes the value: typing ("input-change"), a Clear part ("clear-press"), a form reset ("reset") or a controller ("imperative"). details.cancel() keeps the value as it was.
Where the content scales from, on its trigger's side.
DatePickerContent
<div>data-slot="calendar-day"
PropType
align?Align
How the popup lines up with the anchor along that side. start and end follow the reading direction. How the popup lines up with the input along that side.
Default
"start"
alignOffset?number
Shift along the anchor, in pixels. Shift along the input, in pixels.
Default
0
anchor?string | Anchor | null
Positions the popup against this instead of its trigger: an element, a CSS selector, a point like { x, y }, or anything with getBoundingClientRect(). It's read on every check, so it can move. A controller's open({ anchor }) wins for that open.
Type
string | Anchor | null
arrowPadding?number
Space to keep between the arrow and the popup's corners, in pixels.
Default
6
collisionPadding?number
Space to keep from the viewport edges, in pixels.
Default
8
container?DocumentFragment | Element | null
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
Type
DocumentFragment | Element | null
finalFocus?PopupFocusTarget
Where focus goes when the popup closes while focus is inside it.
Default
"trigger"
keepMounted?boolean
Whether the popup stays in the page, hidden, while closed. Its content keeps its state between opens.
Default
false
side?Side
Which side of the anchor the popup opens on. Flips to the other side when there isn't room. Which side of the input the popup opens on.
Default
"bottom"
sideOffset?number
Gap between the anchor and the popup, in pixels. Gap between the input and the popup, in pixels.
Present while the popup is closed, including while it animates out.
data-ending-style?string
Present while the popup animates out. Style the state you animate to.
data-open?string
Present while the popup is open.
data-presentation"popover" | "sheet"
How the popup presents this time it's open.
Type
"popover" | "sheet"
data-side"top" | "right" | "bottom" | "left"
Where the popup ended up, after flipping away from edges.
Type
"top" | "right" | "bottom" | "left"
data-starting-style?string
Present for the first frame. Style the state you animate from.
CSS variableType
--anchor-heightstring
Height of the anchor.
--anchor-widthstring
Width of the anchor, usually the trigger. Use it to match widths.
--arrow-offsetstring
Where the anchor's center falls along the popup's edge, kept arrowPadding from the corners. Position a ::before arrow with it.
--available-heightstring
Space between the anchor and the viewport edge. Use it for max-height. Not inherited, so a child that needs it copies it on the popup, like [--list-height:var(--available-height)], and reads max-h-(--list-height). The first popup registers both names for the whole page with CSS.registerProperty, so they don't inherit anywhere. A page that needs them to inherit calls it first, with inherits: true. An @property rule can't, since a registration in script wins.
--available-widthstring
Space beside the popup, up to the viewport edge. Not inherited either.
--drawer-dimstring
While it presents as a sheet: how dim the page behind is, from 0 to 1. The backdrop's opacity follows it.
--drawer-expandstring
While it presents as a sheet: 0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel.
--drawer-progressstring
While it presents as a sheet: how far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1.
--drawer-stackstring
While it presents as a sheet: how many sheets opened from inside this one are open above it, rising smoothly as each one opens. Push it back with it.
--sheet-backdropstring
Set it yourself: the color the page dims to while it presents as a sheet. Black at 0.2 by default.
--transform-originstring
The point on the anchor the popup opens from. Use it to scale from the right place.
Logs every state change with its reason to the console, in development builds.
disabled?boolean
Stops presses. The button is natively disabled, so it leaves the tab order and its form doesn't submit through it, unless focusableWhenDisabled is set.
Default
false
focusableWhenDisabled?boolean
Keeps a disabled button in the tab order with aria-disabled instead of the native attribute, so it can hold focus while it becomes disabled and host a tooltip that says why. Presses still do nothing.
Runs when the button is pressed. Return a Promise to keep it pending
(data-pending) until it settles. details.source says how it was
pressed; a wrapper passing the click on may leave it out.
What screen readers hear once the button has been pending for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.
The day, or a month (1 to 12) or year in those views.
Type
DateValue | number
disabled?boolean
Kept for the other bases: a day can't be picked when isDateUnavailable says so.
visibleRange?unknown
Kept for the other bases: the table's offset says which month a day is in.
className?string
Merged with the part's classes.
AttributeType
data-disabled?string
data-focus?string
data-in-range?string
data-outside-range?string
data-selected?string
data-value"${target.value}"
Default
"${target.value}"
data-view?string
Mirrors view.
CSS variableType
--cell-sizestring
DatePickerWeekNumberHeaderCell
<th>data-slot="calendar-week-number-header-cell"
PropType
className?string
Merged with the part's classes.
CSS variableType
--cell-sizestring
DatePickerWeekNumberCell
<th>data-slot="calendar-week-number-cell"
PropType
week?DateValue[]
Kept for the other bases: the row's days.
weekIndex?number
Kept for the other bases: the row's index.
className?string
Merged with the part's classes.
CSS variableType
--cell-sizestring
DatePickerWeekDays
<th>
PropType
format?"narrow" | "short" | "long"
Weekday label width. short is two letters (Su), matching the other
calendar bases, or the whole short name where two letters would repeat
(Arabic and Hebrew short names share their first two).
Type
"narrow" | "short" | "long"
Default
"short"
className?string
Merged with the part's classes.
DatePickerTableDays
DatePickerTableNextMonth
PropType
months?number
The number of months to offset.
Default
1
DatePickerTableMonths
PropType
columns?number
How many months each row holds.
Default
4
format?"short" | "long"
How month names are written: short (Jan) or long (January).