Components
Date Range Picker
Two dates, from one to another, typed or picked in a calendar, with ready-made ranges such as Last 7 days to pick in one press.
Introduction
Date Range Picker is for a period: a stay from the 10th to the 14th, a report for the last 30 days, a sale from one Monday to the next. The user types the two dates, or opens the calendar, presses the first day and then the last, and the days between are joined into a band.
- It is
DatePickerin range mode, built on react-aria's DateRangePicker, and takes the same props: the same limits, sizes, variants and states, and the same text for dates. - It shows two months side by side, which suits a period that crosses a month, and can show one or three.
presetsadds a list of ready-made ranges beside the calendar: Today, Last 7 days, This month and more, or ranges of your own. Pressing one fills the picker and closes the calendar, and the one that matches the value is marked.- The end cannot come before the start. A range cannot run across a day that is unavailable.
- In a form the range is sent as two fields, named with
startNameandendName.
For a single date use DatePicker. It is a Client Component, so a function such as isDateUnavailable must be defined in a client file. The ready-made ranges are worked out from today, in the browser, when the calendar opens.
Installation
centerUI has no CLI or registry yet: components are copied into your project. It also needs @internationalized/date, which react-aria uses for dates.
# bun
bun add react-aria-components @internationalized/date tailwind-variants tailwind-merge clsx
# pnpm
pnpm add react-aria-components @internationalized/date tailwind-variants tailwind-merge clsx
# npm
npm install react-aria-components @internationalized/date tailwind-variants tailwind-merge clsxManual installation
Copy these files into your project and keep the paths, or adjust the imports. Date Range Picker is Date Picker in range mode, so it needs Date Picker and what that needs.
1. Add Date Picker
Its component and styles, and Calendar, as described on their pages.
src/components/ui/date-picker/date-picker.tsxShow code
"use client";
import {
type CalendarDate,
type DateValue,
parseDate,
} from "@internationalized/date";
import {
type ReactNode,
useContext,
useMemo,
useSyncExternalStore,
} from "react";
import {
Calendar as AriaCalendar,
DatePicker as AriaDatePicker,
type DatePickerProps as AriaDatePickerProps,
DateRangePicker as AriaDateRangePicker,
RangeCalendar as AriaRangeCalendar,
DateInput,
DateRangePickerStateContext,
DateSegment,
Dialog,
FieldError,
Group,
Label,
Popover,
Text,
type ValidationResult,
} from "react-aria-components";
import { CalendarIcon } from "@/components/icons";
import { Button } from "@/components/ui/button/button";
import {
CalendarBody,
type CalendarDateText,
type CalendarRange,
createUnavailable,
RangePresetList,
} from "@/components/ui/calendar/calendar";
import { cn } from "@/lib/cn";
import { calendarStyles } from "@/types/calendar-styles";
import { datePickerStyles } from "@/types/date-picker-styles";
import type { DateRangePresetInput } from "@/types/date-range-presets";
import { popoverStyles } from "@/types/popover-styles";
export {
type DateRangePreset,
type DateRangePresetInput,
type DateRangePresetKey,
defaultDateRangePresets,
} from "@/types/date-range-presets";
type Placement = "bottom start" | "bottom end" | "top start" | "top end";
interface BaseProps
extends Pick<
AriaDatePickerProps<DateValue>,
| "isDisabled"
| "isReadOnly"
| "isInvalid"
| "isRequired"
| "autoFocus"
| "name"
| "form"
| "aria-label"
| "aria-labelledby"
| "isOpen"
| "defaultOpen"
| "onOpenChange"
| "shouldCloseOnSelect"
| "onFocus"
| "onBlur"
> {
label?: ReactNode;
/** Help text under the field. */
description?: ReactNode;
/** Shown when the field is invalid. A function receives the validation result. */
errorMessage?: string | ((validation: ValidationResult) => string);
/** The earliest date that can be picked, such as `"2026-01-01"`. */
minValue?: CalendarDateText;
/** The latest date that can be picked. */
maxValue?: CalendarDateText;
/** Dates that cannot be picked, such as days that are booked. */
unavailableDates?: CalendarDateText[];
/** Days of the week that cannot be picked, from 0 (Sunday) to 6 (Saturday). */
disabledWeekdays?: number[];
/** Decides for each date if it cannot be picked. Called with `"2026-03-15"`. */
isDateUnavailable?: (date: CalendarDateText) => boolean;
/** The date an empty field, and its calendar, start from. Defaults to today. */
placeholderValue?: CalendarDateText;
/** Show the month and the day with two digits, such as 03/05 instead of 3/5. */
showLeadingZeros?: boolean;
/** Replaces the calendar icon of the button. */
icon?: ReactNode;
/** Which side of the field the calendar opens on, and which edge it lines up with. Defaults to `bottom start`. */
placement?: Placement;
/** How many months the calendar shows side by side, from 1 to 3. Defaults to 1. */
visibleMonths?: 1 | 2 | 3;
/** The first day of the week. Defaults to the one of the user's language. */
firstDayOfWeek?: "sun" | "mon" | "tue" | "wed" | "thu" | "fri" | "sat";
/** What the arrows of the calendar move by. Defaults to `visible`. */
pageBehavior?: "visible" | "single";
/** Days of the neighbouring months in the calendar. Defaults to `false`. */
showOutsideDays?: boolean;
/** A "Today" button in the calendar. Defaults to `false`. */
showTodayButton?: boolean;
/** The text of that button. Defaults to "Today". */
todayLabel?: string;
variant?: "outline" | "secondary" | "ghost";
size?: "sm" | "md" | "lg";
className?: string;
}
interface SingleProps {
/** One date (the default), or a range from one date to another. */
selectionMode?: "single";
/** The date as text, `"2026-03-15"`, or `null` while it is not complete. For a controlled picker. */
value?: CalendarDateText | null;
/** The date to start with, for an uncontrolled picker. */
defaultValue?: CalendarDateText | null;
onChange?: (value: CalendarDateText | null) => void;
}
interface RangeProps {
selectionMode: "range";
/** Ranges offered in a list beside the calendar, to pick in one press: the names of ready-made ones, or ranges of your own. Ready-made ranges are worked out from today. */
presets?: DateRangePresetInput[];
/** The name of the form field that holds the start, such as `"from"`. A range is sent as two fields, this and `endName`. */
startName?: string;
/** The name of the form field that holds the end, such as `"to"`. */
endName?: string;
/** The range, `{ start: "2026-03-10", end: "2026-03-14" }`, or `null` while it is not complete. */
value?: CalendarRange | null;
defaultValue?: CalendarRange | null;
onChange?: (value: CalendarRange | null) => void;
}
export type DatePickerProps = BaseProps & (SingleProps | RangeProps);
/** The props of a range picker. */
export type DatePickerRangeProps = Extract<
DatePickerProps,
{ selectionMode: "range" }
>;
function toDate(text: string | null | undefined) {
if (!text) return null;
try {
return parseDate(text);
} catch {
return null;
}
}
function toRange(range: CalendarRange | null | undefined) {
const start = toDate(range?.start);
const end = toDate(range?.end);
return start && end ? { start, end } : null;
}
// The ready-made ranges beside the calendar. Pressing one fills the picker and
// closes the calendar. It reads and sets the picker through its state.
function Presets({
presets,
min,
max,
className,
buttonClassName,
}: {
presets: DateRangePresetInput[];
min?: CalendarDate;
max?: CalendarDate;
className: string;
buttonClassName: string;
}) {
const state = useContext(DateRangePickerStateContext);
const picked = state?.value;
return (
<RangePresetList
presets={presets}
value={
picked?.start && picked.end
? { start: picked.start, end: picked.end }
: null
}
min={min}
max={max}
className={className}
buttonClassName={buttonClassName}
onPick={(range) => {
state?.setValue(range);
state?.setOpen(false);
}}
/>
);
}
/**
* A field for a date with a calendar behind a button: the user can type the date
* in the field, part by part, or open the calendar and pick a day. Set
* `selectionMode="range"` to pick two dates, from one to another. It is a
* `DateField` and a `Calendar` in one, built on react-aria's DatePicker, so the
* keyboard, the screen reader announcements, the language of the days and
* months, and form submission (`name`) all come from there.
*
* The value is plain text, `"2026-03-15"`, the same as `DateField` and
* `Calendar`, and `{ start, end }` of two of them for a range. It is `null`
* until every part is filled. A date has no time and no time zone.
*
* @example
* <DatePicker label="Check-in" defaultValue="2026-03-15" onChange={setCheckIn} />
* <DatePicker selectionMode="range" label="Stay" onChange={setStay} />
*/
export function DatePicker(props: DatePickerProps) {
const {
label,
description,
errorMessage,
minValue,
maxValue,
unavailableDates,
disabledWeekdays,
isDateUnavailable,
placeholderValue,
showLeadingZeros,
icon,
placement = "bottom start",
visibleMonths = 1,
firstDayOfWeek,
pageBehavior,
showOutsideDays = false,
showTodayButton = false,
todayLabel = "Today",
variant,
size = "md",
className,
...rest
} = props;
const isRange = props.selectionMode === "range";
const styles = datePickerStyles({ variant, size });
const calendarClasses = calendarStyles({
variant: "plain",
size: "md",
mode: isRange ? "range" : "single",
showOutsideDays,
});
// False on the server and while the page hydrates, true after.
const isClient = useSyncExternalStore(
() => () => {},
() => true,
() => false,
);
const min = useMemo(() => toDate(minValue) ?? undefined, [minValue]);
const max = useMemo(() => toDate(maxValue) ?? undefined, [maxValue]);
const placeholder = useMemo(
() => toDate(placeholderValue) ?? undefined,
[placeholderValue],
);
const unavailable = createUnavailable(
unavailableDates,
disabledWeekdays,
isDateUnavailable,
);
// What `AriaDatePicker` and `AriaDateRangePicker` share.
const shared = {
isDisabled: rest.isDisabled,
isReadOnly: rest.isReadOnly,
isInvalid: rest.isInvalid,
isRequired: rest.isRequired,
autoFocus: rest.autoFocus,
name: rest.name,
form: rest.form,
"aria-label": rest["aria-label"],
"aria-labelledby": rest["aria-labelledby"],
isOpen: rest.isOpen,
defaultOpen: rest.defaultOpen,
onOpenChange: rest.onOpenChange,
shouldCloseOnSelect: rest.shouldCloseOnSelect,
onFocus: rest.onFocus,
onBlur: rest.onBlur,
minValue: min,
maxValue: max,
placeholderValue: placeholder,
isDateUnavailable: unavailable,
granularity: "day" as const,
shouldForceLeadingZeros: showLeadingZeros,
firstDayOfWeek,
// Show a problem while the user types, not only on submit.
validationBehavior: "aria" as const,
className: cn("group/date-picker flex w-full flex-col gap-1.5", className),
};
const labelEl = label ? (
<Label className="text-sm font-medium group-data-required/date-picker:after:ml-0.5 group-data-required/date-picker:after:text-danger group-data-required/date-picker:after:content-['*']">
{label}
</Label>
) : null;
const trigger = (
<Button
variant="ghost"
isIcon
size={size === "lg" ? "sm" : "xs"}
className={styles.trigger()}
>
{icon ?? <CalendarIcon />}
</Button>
);
const below = (
<>
{description ? (
<Text slot="description" className="text-sm text-muted-fg">
{description}
</Text>
) : null}
<FieldError className="text-sm text-danger">{errorMessage}</FieldError>
</>
);
const panel = (
<Popover
placement={placement}
className={popoverStyles({ size: "auto" }).popover()}
>
<Dialog className={styles.dialog()}>
<div className={styles.panel()}>
{props.selectionMode === "range" && props.presets?.length ? (
<Presets
presets={props.presets}
min={min}
max={max}
className={styles.presets()}
buttonClassName={styles.preset()}
/>
) : null}
{isRange ? (
<AriaRangeCalendar
visibleDuration={{ months: visibleMonths }}
pageBehavior={pageBehavior}
className={calendarClasses.root()}
>
<CalendarBody
styles={calendarClasses}
visibleMonths={visibleMonths}
showTodayButton={showTodayButton}
todayLabel={todayLabel}
/>
</AriaRangeCalendar>
) : (
<AriaCalendar
visibleDuration={{ months: visibleMonths }}
pageBehavior={pageBehavior}
className={calendarClasses.root()}
>
<CalendarBody
styles={calendarClasses}
visibleMonths={visibleMonths}
showTodayButton={showTodayButton}
todayLabel={todayLabel}
/>
</AriaCalendar>
)}
</div>
</Dialog>
</Popover>
);
const segments = (slot?: "start" | "end") =>
isClient ? (
<DateInput slot={slot} className={styles.input()}>
{(segment) => (
<DateSegment segment={segment} className={styles.segment()} />
)}
</DateInput>
) : (
// The segments are in the order and the language of the user, which the
// server does not know, so they are drawn in the browser only and the
// frame keeps its place until then.
<div aria-hidden="true" className={styles.input()} />
);
if (props.selectionMode === "range") {
return (
<AriaDateRangePicker
{...shared}
startName={props.startName}
endName={props.endName}
{...(props.value !== undefined
? { value: toRange(props.value) }
: { defaultValue: toRange(props.defaultValue) })}
onChange={(next) =>
props.onChange?.(
next
? { start: next.start.toString(), end: next.end.toString() }
: null,
)
}
>
{labelEl}
<Group className={styles.frame()}>
{segments("start")}
<span aria-hidden="true" className={styles.dash()}>
–
</span>
{segments("end")}
{trigger}
</Group>
{below}
{panel}
</AriaDateRangePicker>
);
}
return (
<AriaDatePicker
{...shared}
{...(props.value !== undefined
? { value: toDate(props.value) }
: { defaultValue: toDate(props.defaultValue) })}
onChange={(next) => props.onChange?.(next ? next.toString() : null)}
>
{labelEl}
<Group className={styles.frame()}>
{segments()}
{trigger}
</Group>
{below}
{panel}
</AriaDatePicker>
);
}2. Add the Date Range Picker file
src/components/ui/date-range-picker/date-range-picker.tsxShow code
"use client";
import {
DatePicker,
type DatePickerRangeProps,
} from "@/components/ui/date-picker/date-picker";
/** The props of `DatePicker` in range mode, less `selectionMode`, which is always `range`. */
export type DateRangePickerProps = Omit<DatePickerRangeProps, "selectionMode">;
/**
* A field for a range of dates, from one to another, with a calendar behind a
* button: type the two dates, or open the calendar, press the first day and
* then the last, and the days between are joined into a band. It shows two
* months side by side, and can offer ready-made ranges such as "Last 7 days" or
* "This month" in a list beside the calendar, to pick in one press.
*
* It is `DatePicker` in range mode, and takes the same props, so it is built on
* react-aria's DateRangePicker: the keyboard, the screen reader announcements,
* the language of the days and months, and form submission all come from there.
* The value is `{ start, end }`, two dates as text, and `null` until both are
* filled. The end may not come before the start.
*
* @example
* <DateRangePicker
* label="Report period"
* presets={["last7", "last30", "thisMonth"]}
* onChange={setPeriod}
* />
*/
export function DateRangePicker({
visibleMonths = 2,
...props
}: DateRangePickerProps) {
return (
<DatePicker
selectionMode="range"
visibleMonths={visibleMonths}
{...props}
/>
);
}3. Use it
import { DateRangePicker } from "@/components/ui/date-range-picker/date-range-picker";Anatomy
A framed row of two dates with a button at its end, and a popover with presets and a calendar.
<DateRangePicker
label="Report period"
presets={["last7", "last30", "thisMonth"]}
defaultValue={{ start: "2026-03-01", end: "2026-03-31" }}
/>| Part | Rendered as | Notes |
|---|---|---|
| Label | label | Names the picker. Clicking it focuses the first segment. |
| Start and end | spinbutton | Two sets of segments, month, day and year, with a dash between them. |
| Button | button | A calendar icon that opens the calendar. |
| Presets | button group | Ready-made ranges in a list beside the calendar, or above it on a narrow screen. The one that matches the value is marked. |
| Calendar | popover, dialog | Two months side by side. The days of the range are joined into a band, and its ends are marked. |
Without a label, give the picker an aria-label so a screen reader can name it.
Value
A range is two dates as text, each with the year first.
// A range: two dates as text, year first
{ start: "2026-03-10", end: "2026-03-14" }
null // nothing picked, or not complete yetThe value is null until both dates are filled, so an unfinished range is never reported as a wrong one.
Keyboard
Everything can be done without a mouse.
| Key | What it does |
|---|---|
| Type digits | Fill the segment that has focus, in the start or the end. Focus moves on when it is full. |
| Arrow Left, Arrow Right | Move to the previous or the next segment, from the start into the end. |
| Enter, Space | On the button, open the calendar. In the calendar, the first press sets the start and the second sets the end. |
| Arrows, Page Up, Page Down | In the calendar, move by a day, a week, a month. With the start set, the band follows the focus. |
| Escape | Forget a start that was pressed and begin again. Press it again to close the calendar. |
Examples
Usage
Type two dates, or press the calendar button, then the first day and the last.
Default value
Start with a range. The calendar opens on the month of its start.
Controlled
Keep the range in your own state with value and onChange. It is null while a date is missing.
Mar 10, 2026 to Mar 14, 2026, 5 days
Ready-made ranges
presets lists the names of ready-made ranges. They are worked out from today when the calendar opens, and the one that matches the value is marked.
| Name | Range |
|---|---|
| today | Today |
| yesterday | Yesterday |
| last7 | Last 7 days, ending today |
| last14 | Last 14 days |
| last30 | Last 30 days |
| last90 | Last 90 days |
| thisMonth | This month, from the 1st to its last day |
| lastMonth | The whole of the month before |
| thisYear | This year, from January 1 to December 31 |
import { defaultDateRangePresets } from "@/components/ui/date-picker/date-picker";
<DateRangePicker presets={defaultDateRangePresets} ... />Ranges of your own
Mix in ranges of your own with a label and a fixed range, such as quarters of a fiscal year.
Minimum and maximum
Days outside the limits are dimmed, and a ready-made range that goes outside them is disabled.
Your own rule
isDateUnavailable is called with each date as text. Here nothing is delivered on the 13th, so no range can include it.
How many months
Two months side by side by default. Use one for a narrow place, or three for a long period.
In a form
A range is sent as two fields. Name them with startName and endName.
Sizes
Variants
Disabled and read only
A disabled picker cannot be used at all. A read only one shows its range and can be focused, but not changed.
Validation
For a rule of your own, such as a longest stay, set isInvalid with an errorMessage. The field gets a red border and the message shows under it.
Component API
Date Range Picker takes the props below, which are those of Date Picker in range mode.
| Prop | Type | Default |
|---|---|---|
| label | ReactNode | - |
| description | ReactNode | - |
| errorMessage | string | (validation) => string | - |
| value | { start: string, end: string } | null | - |
| defaultValue | { start: string, end: string } | null | - |
| onChange | (value: { start, end } | null) => void | - |
| presets | (DateRangePresetKey | { label, value })[] | - |
| minValue | string | - |
| maxValue | string | - |
| unavailableDates | string[] | - |
| disabledWeekdays | number[] | - |
| isDateUnavailable | (date: string) => boolean | - |
| placeholderValue | string | today |
| showLeadingZeros | boolean | the language's |
| icon | ReactNode | a calendar |
| placement | "bottom start" | "bottom end" | "top start" | "top end" | "bottom start" |
| visibleMonths | 1 | 2 | 3 | 2 |
| firstDayOfWeek | "sun" | "mon" | ... | "sat" | the user's language |
| pageBehavior | "visible" | "single" | "visible" |
| showOutsideDays | boolean | false |
| showTodayButton | boolean | false |
| todayLabel | string | "Today" |
| isOpen | boolean | - |
| defaultOpen | boolean | false |
| onOpenChange | (isOpen: boolean) => void | - |
| shouldCloseOnSelect | boolean | true |
| startName | string | - |
| endName | string | - |
| variant | "outline" | "secondary" | "ghost" | "outline" |
| size | "sm" | "md" | "lg" | "md" |
| autoFocus | boolean | false |
| isDisabled | boolean | false |
| isReadOnly | boolean | false |
| isInvalid | boolean | false |
| isRequired | boolean | false |
| aria-label | string | - (when there is no label) |