DatePicker
AlphaAn accessible date picker with calendar grid navigation, single and range selection modes, and keyboard-first design following the ARIA date picker pattern.
Import
import { DatePicker } from "@compa11y/react";Usage
Example.tsx
import { useState } from "react";
import { DatePicker, Button, Text } from "@compa11y/react";
// Single date
function BirthdayPicker() {
const [date, setDate] = useState<Date>();
return (
<div>
<Text as="label" size="sm" weight="semibold">Birthday</Text>
<DatePicker value={date} onValueChange={setDate}>
<DatePicker.Input placeholder="DD/MM/YYYY" />
<DatePicker.Trigger>
<Button variant="ghost" size="sm">Pick date</Button>
</DatePicker.Trigger>
<DatePicker.Calendar />
</DatePicker>
</div>
);
}
// Date range
function BookingDateRange() {
const [range, setRange] = useState<[Date, Date]>();
return (
<DatePicker
mode="range"
value={range}
onValueChange={setRange}
minDate={new Date()}
>
<DatePicker.RangeInputs />
<DatePicker.Calendar />
</DatePicker>
);
}Features
- Single date and date range selection
- Full keyboard navigation in calendar grid
- Day, month, and year precision views
- Popover or modal overlay modes
- Min/max date constraints
- Screen reader announcements for date changes
- Compound component API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | Date | [Date, Date] | - | Controlled value (single Date or [start, end] range) |
onValueChange | (value: Date | [Date, Date]) => void | - | Called when date selection changes |
mode | 'single' | 'range' | 'single' | Selection mode |
precision | 'day' | 'month' | 'year' | 'day' | Calendar precision |
overlay | 'popover' | 'modal' | 'popover' | Overlay type |
minDate | Date | - | Earliest selectable date |
maxDate | Date | - | Latest selectable date |
disabled | boolean | false | Disables the date picker |
Sub-components
DatePicker.Input
| Prop | Type | Default | Description |
|---|---|---|---|
placeholder | string | - | Input placeholder |
DatePicker.Trigger
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | Calendar icon button |
DatePicker.Calendar
Keyboard Interactions
Accessibility
All keyboard interactions follow WAI-ARIA best practices and work without any additional configuration.
| Key | Action |
|---|---|
| ArrowLeft / ArrowRight | Move to previous/next day |
| ArrowUp / ArrowDown | Move to same day in previous/next week |
| Home / End | Move to first/last day of the week |
| PageUp / PageDown | Move to same day in previous/next month |
| Enter / Space | Select the focused date |
| Escape | Close the calendar overlay |