Datepicker
A composable date picker with masked input, popup calendar, and support for single, range, and dual-range selection.
Features
- Input with masked entry
- Popup calendar
- Single, range & dual-range modes
- Controlled or uncontrolled
- Focus management
- Headless styling
Installation
npm install @ariaui/datepicker
Examples
Three playgrounds: single date (MDY mask), range with an adjacent time Select, and dual-range (two-pane) stay picker. Calendar styling reuses the same token-backed class maps as the Calendar docs page.
Compatible host composition
Root, Label, Calendar, and the five split header parts can adopt one compatible native host with asChild (default false). Props and the native ref must reach that one element. Root state and Calendar behavior stay owned by the primitives; Input and generated CalendarBody/month/year selectors do not become replacement APIs.
Use a real label with htmlFor matching the native input ID. Custom month/year children own their text, so this example keeps them synchronized with the controlled visible month. Normal headers still generate their default content. Child cancellation, class/style merging, and native button activation remain intact.
The effective label host ID names both input and popup and follows ID/host replacement. A root-disabled adopted Calendar retains its inert boundary despite contradictory child flags. Native HTML refs remain narrow; arbitrary hosts and SVG boxes are not supported. daysInWeek remains required. See the API reference for each part's native host.
Single date
Uncontrolled single value, MDY mask, and a styled calendar popover.
No preview output yet.
Date range + time
Range mode with ISO-shaped input text; a separate Select demonstrates pairing time with the same row.
No preview output yet.
Dual-range
Hotel-style stay picker: dual-range calendar with shared navigation icons.
No preview output yet.
Framer Motion
Single datepicker content animated with Framer Motion through Content asChild composition.
No preview output yet.
Anatomy
import * as Datepicker from "@ariaui/datepicker";
export default function Example() {
return (
<Datepicker.Root>
<Datepicker.Label />
<Datepicker.Input />
<Datepicker.Trigger />
<Datepicker.Content>
<Datepicker.Calendar>
<Datepicker.CalendarHeader>
<Datepicker.CalendarPrevious />
<Datepicker.CalendarMonth />
<Datepicker.CalendarYear />
<Datepicker.CalendarNext />
</Datepicker.CalendarHeader>
<Datepicker.CalendarBody />
</Datepicker.Calendar>
</Datepicker.Content>
</Datepicker.Root>
);
}
API Reference
Root
State container. Owns open state, value state, visible month, and input masking configuration.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
mode | "single" | "range" | "dual-range" | "single" |
open | boolean | — |
defaultOpen | boolean | false |
onOpenChange | (open: boolean) => void | — |
value | Date | { start?: Date; end?: Date } | — |
defaultValue | Date | { start?: Date; end?: Date } | — |
onValueChange | (value: DatepickerValue) => void | — |
visibleMonth | Date | — |
defaultVisibleMonth | Date | new Date() |
onVisibleMonthChange | (month: Date) => void | — |
disabled | boolean | false |
readOnly | boolean | false |
closeOnSelect | boolean | true |
inputMask | "mdy" | "iso" | "custom" | — |
parseInput | (text: string, mode: DatepickerMode) => DatepickerValue | — |
formatInput | (value: DatepickerValue, mode: DatepickerMode) => string | — |
Label
Visible label. The actual host ID labels the native input and popup; live host ID changes and retiring labels keep the relationship current.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Trigger
Toggles the picker open and closed. Acts as the fallback positioning reference when input ref is unavailable.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
| Attribute | Values |
|---|---|
| aria-haspopup | dialog |
| aria-expanded | "true" when picker is open |
| [data-state] | "open" | "closed" |
Input
Native input reflecting the formatted date value. Supports masked entry and commits on Enter/blur. No asChild host substitution.
| Prop | Type | Default |
|---|---|---|
placeholder | string | — |
| Attribute | Values |
|---|---|
| aria-haspopup | dialog |
Content
Floating picker surface. Portals to the body, positions relative to the input, and manages focus on open/close.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
| Attribute | Values |
|---|---|
| role | dialog |
Calendar
Embedded calendar bound to the datepicker state. Wraps @ariaui/calendar with shared mode, value, and visible month.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
daysInWeek* | Record<string, string> | — |
classNames | object | — |
CalendarHeader
Header row for the embedded calendar containing navigation and month/year labels.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
CalendarPrevious
Button to navigate to the previous month.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
CalendarMonth
Renders the current visible month label.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
CalendarMonthSelect
Generated month selector, not an asChild target. Closes before the datepicker content when both need to dismiss.
| Prop | Type | Default |
|---|---|---|
triggerClassName | string | — |
contentClassName | string | — |
optionClassName | string | — |
icon | React.ReactNode | — |
checkIcon | React.ReactNode | — |
contentWrapper | (children: React.ReactNode) => React.ReactNode | — |
| Attribute | Values |
|---|---|
| aria-haspopup | listbox |
CalendarYear
Renders the current visible year label.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
CalendarYearSelect
Generated year selector, not an asChild target. Closes before the datepicker content when both need to dismiss.
| Prop | Type | Default |
|---|---|---|
years | number[] | current year ± 10 |
triggerClassName | string | — |
contentClassName | string | — |
optionClassName | string | — |
icon | React.ReactNode | — |
checkIcon | React.ReactNode | — |
contentWrapper | (children: React.ReactNode) => React.ReactNode | — |
| Attribute | Values |
|---|---|
| aria-haspopup | listbox |
CalendarNext
Button to navigate to the next month.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
CalendarBody
Generates the date grid, or two panes in dual-range mode. No asChild host substitution; native table ancestry stays owned by Calendar.
Keyboard
| Shortcut | Action |
|---|---|
| Enter | Commit the typed input value. Select the focused date in the calendar. |
| Esc | Close the picker and return focus to the trigger. |
| Tab | Move focus between input, trigger, and calendar controls. |
| ↓ | Move to the same day in the next week (inside the calendar grid). |
| ↑ | Move to the same day in the previous week (inside the calendar grid). |
| ← | Move to the previous day (inside the calendar grid). |
| → | Move to the next day (inside the calendar grid). |
| Home | Move to the first day of the current week. |
| End | Move to the last day of the current week. |
Accessibility
The Datepicker component implements the WAI-ARIA Date Picker Dialog pattern:
Triggerexposesaria-haspopup="dialog"andaria-expandedto announce the popup calendar.Inputalso carriesaria-haspopup="dialog"for assistive technology awareness.Contentrenders as adialogrole and is labelled by the sharedLabel.- Focus moves into the popup when it opens and restores to the trigger when it closes.
Escapecloses the popup from any focusable element inside it.- Date-grid keyboard navigation (arrow keys, Home, End) is delegated to the embedded
@ariaui/calendar.