Skip to Content

React Date Range Picker

Select a local calendar date range with accessible keyboard interaction, validation, localized labels, and optional multi-month display.

Stable API maturity: Stable. The range picker is a UI control; it does not calculate rates, query availability, or submit reservations.

DateRangePicker is the generic @puzzle-ui/ui control for selecting a start and end calendar date. Use it when the two dates should share range highlighting and keyboard behavior. For a single date, use DatePicker. For accommodation availability and stay rules, use AvailabilityCalendar.

Import

import {
  DateRangePicker,
  type DateRange,
  type DateRangePickerProps,
} from "@puzzle-ui/ui";

Basic and uncontrolled usage

Dates are local calendar values. Construct them with new Date(year, monthIndex, day) and avoid serializing a calendar day with toISOString().

<DateRangePicker
  label="Stay dates"
  locale="en-GB"
  defaultValue={{ start: new Date(2025, 2, 15), end: null }}
  placeholder="Choose a stay"
/>
390 × 844

Controlled ranges

Use value and onChange when the application owns the selection. The callback reports a new DateRange after the start date is chosen and again when a complete range is selected.

const [range, setRange] = useState<DateRange>({
  start: null,
  end: null,
});

<DateRangePicker
  label="Dates"
  value={range}
  onChange={setRange}
  clearable
  months={2}
/>;

Constraints and extensions

minDate, maxDate, disabledDates, and shouldDisableDate prevent dates from being selected. Use validateRange for application-local rules such as a minimum stay. The callback should return an error message for invalid complete ranges; the final availability check remains the application's responsibility.

dayContent adds small, non-interactive content such as a price or availability marker. The picker owns the actual day button and its accessible semantics.

Locale and responsive behavior

Pass a BCP 47 locale to format dates, month names, weekdays, and numbers. weekStartsOn overrides the locale's first day when the application needs a specific calendar convention. months={2} shows two months on wider screens and collapses to one month on narrow screens. size and fullWidth accept Puzzle responsive values.

Accessibility and SSR

The control uses a labeled button, a semantic calendar grid, accessible day names, visible focus, keyboard navigation, disabled states, and Escape/outside close behavior from the existing UI popout. Arrow keys move by day or week, Home/End move within a week, Page Up/Page Down change months, and Enter or Space selects a date. Dates are normalized from local calendar fields, so daylight-saving and timezone offsets do not shift the selected day. Browser globals are used only by interactive event handling; the initial markup is SSR-safe.

API

PropTypeDescription
value, defaultValueDateRange | nullControlled or initial range.
onChange(value: DateRange) => voidReceives partial and complete selections.
label, placeholder, startPlaceholder, endPlaceholderReactNodeField and selection text.
minDate, maxDate, disabledDates, shouldDisableDateDate constraintsPrevent invalid day choices.
validateRange(range: DateRange) => ReactNode | undefinedValidates a complete local range.
months1 | 2Number of visible months.
dayContent(date, state) => ReactNodeAdds passive day information.
locale, weekStartsOn, dateFormatLocalization optionsControl calendar and date formatting.
clearable, required, disabledbooleanField state and clearing behavior.

Use FormField for additional form composition. Use Select for bounded non-date choices.