Date picker
Picks a day or a range from a calendar, with a quick year.
Presets
Most people click Last 30 days rather than pick two dates, so presets come first: a list before the calendar, at its side where both fit, above it where they don't, as in this column (full screen shows them side by side).datePresets holds today, tomorrow,nextWeek, last7Days, last30Days and thisQuarter, worded through SatinLabels; a preset of your own is a label and a day, a range, or a function of today. Picking one moves the calendar to its month; a range still waits for Apply. A range picked by hand is a custom range, and no preset stays selected.
The week starts where the dateLocale label's locale starts it (Sunday in en-US, Monday in pl-PL), for the calendar and for Next week alike; weekStartsOn pins it.
Installation
npm i @uisatin/uiimport { DatePicker, DatePickerPanel } from '@uisatin/ui/date-picker'About 55.5 kB of JavaScript, minified and gzipped, with what it imports (React aside). The stylesheet is one file for every component.
npx shadcn@latest add https://uisatin.dev/r/date-picker.jsonAdds date-picker.tsx, button.tsx, dropdown.tsx, form-field.tsx, kbd.tsx, labels.tsx, pointer-modality.tsx, select.tsx and spinner.tsx to components/ui and installs iconoir-react and radix-ui.
First time with Satin? Set it up once, styles and fonts included, with the installation guide.
API Reference
DatePicker and DateRangePicker are fields with the Input skin that open a Calendar in a popover. The range picker waits for Apply. Calendar works on its own too, as one month or two. presets lists shortcuts before the calendar; datePresets holds the common ones. The week starts where the dateLocale starts it, or on weekStartsOn. isDisabled(date) rules out days besides min/max; they fade but stay reachable with the arrow keys. renderDay(date, state) draws each day: return a CalendarDay, the default day button, with your own children, aria-label or a Tooltip around it. Every picker passes weekStartsOn, isDisabled and renderDay on to its Calendar.
| Prop | Type | Default |
|---|---|---|
DatePicker.value | Datenull | — |
DatePicker.defaultValue | Datenull | — |
DatePicker.onValueChange | (value: Date) => void | — |
DateRangePicker.value | { from: Date | null, to: Date | null } | — |
DateRangePicker.defaultValue | DateRange | — |
DateRangePicker.onValueChange | (range: DateRange) => void | — |
Calendar.mode | "single""range" | "single" |
Calendar.header | "title""picker" | "title" |
Calendar.months | 12 | 1 |
min / max | Date | — |
today | Date | — |
presets | DatePreset[] | — |
weekStartsOn | 0123456 | locale |
isDisabled | (date: Date) => boolean | — |
renderDay | (date: Date, state: CalendarDayState) => ReactNode | — |
label / hint / error | ReactNode | — |
Accessibility
Both pickers are a button named by label and described by the hint or error (aria-describedby, aria-invalid); it opens the Calendar in a popover and moves focus into it. Each month is a grid labelled by its title, and the grid is one tab stop. Each day is a button named by its full date; picked days have aria-selected and today aria-current="date". Days that can't be picked (outside min/max, or isDisabled) have aria-disabled rather than disabled, so the arrow keys still reach them and a reason drawn with renderDay is heard and seen; Enter and clicks do nothing there. The arrows are named "Previous month" and "Next month", and the year Select "Year". Presets come before the calendar as a listbox named "Presets", one tab stop; each preset is an option named by its label, the one matching the value aria-selected, one outside min and max (or, in DatePicker, on a day isDisabled rules out) aria-disabled. Picking a preset moves the calendar to its month.
| Key | Action |
|---|---|
| EnterorSpace | On the field: opens the calendar. On a day: picks it; a range takes its start, then its end. |
| ←or→ | Moves a day back or forward, turning the month when needed. |
| ↑or↓ | Moves a week back or forward. |
| Page UporPage Down | Moves a month back or forward. |
| HomeorEnd | Moves to the first or the last day of the week (from the locale, or weekStartsOn). In the presets: to the first or the last preset. |
| ↑or↓ | In the presets: moves to the previous or the next preset without picking it (← and → too, where the list runs in a row). |
| EnterorSpace | On a preset: picks it. DatePicker closes; a range picker shows the range and waits for Apply. |
| TaborShift+Tab | Moves between the presets, the arrows, the year, the days and, in a range, Cancel and Apply. |
| Esc | Closes the calendar and returns focus to the field; a range not yet applied is dropped. |
Something wrong or missing on this page?
Report a problemSuggest an improvement