DateRangePicker

A date range picker with dual-month calendar, presets, external navigation, URL sync, and form integration.

Installation

CLI

Loading...

Dependencies

This component requires the following npm packages:

Loading...

Registry Dependencies

This component also requires: https://ui.shadcn.com/r/styles/base-vega/button.json, https://ui.shadcn.com/r/styles/base-vega/calendar.json, https://ui.shadcn.com/r/styles/base-vega/popover.json, https://ui.shadcn.com/r/styles/base-vega/utils.json

Usage

DateRangePicker is a highly configurable compound component for selecting date ranges. It features a dual-month calendar, preset options, external navigation controls, built-in i18n support, and SSR-friendly URL sync capabilities.

The component uses a compound component pattern, allowing you to customize the trigger, navigation, calendar, presets, and actions independently. It supports both controlled and uncontrolled usage patterns.

Examples

With Presets

Enable the presets sidebar with commonly used date ranges like "Current Month", "Last 3 Months", etc.

With Action Buttons

Add Clear, Cancel, and Apply buttons for explicit user confirmation. Set closeOnSelect to false to keep the popover open until the user clicks Apply.

Single Month

Use a single month calendar for a more compact layout. The external navigation arrows select the full previous/next month. Use the calendar's internal navigation to browse months without changing the selection.

German Locale (i18n)

Use date-fns locales for calendar display and the built-in getLocalizedPresets function for translated preset labels. Supports English, German, French, and Spanish out of the box.

Constrained Date Range

Limit selectable dates with minDate and maxDate props. Navigation buttons are automatically disabled when at the boundaries.

Fully Controlled

Control both the date range value and popover open state externally for full control over the component behavior.

From:Not selected
To:Not selected
Picker state:Closed

API Reference

DateRangePicker Props

PropTypeDefaultDescription
valueDateRange-The controlled value of the selected date range ({ from: Date, to?: Date }).
defaultValueDateRange-The default value of the selected date range.
onValueChange(value: DateRange | undefined) => void-Callback fired when the date range selection changes.
openboolean-The controlled open state of the popover.
defaultOpenbooleanfalseThe default open state of the popover.
onOpenChange(open: boolean) => void-Callback fired when the popover open state changes.
monthDate-The controlled month displayed in the calendar.
defaultMonthDate-The default month to display in the calendar.
onMonthChange(month: Date) => void-Callback fired when the displayed month changes.
dateFormatstring"dd.MM.yyyy"The date format string (date-fns format).
dateSeparatorstring" - "The separator between from and to dates in display.
placeholderstring"Select date range"Placeholder text when no date is selected.
localeLocale-date-fns locale for formatting and calendar display.
presetsDateRangePreset[]-Custom preset options. Defaults to built-in presets (Current Month, Last Month, etc.).
onPresetSelect(preset: DateRangePreset) => void-Callback fired when a preset is selected.
numberOfMonthsnumber2Number of months to display in the calendar.
minDateDate-Minimum selectable date.
maxDateDate-Maximum selectable date.
disabledMatcher | Matcher[]-Days that cannot be selected (react-day-picker Matcher).
weekStartsOn0 | 1 | 2 | 3 | 4 | 5 | 61First day of the week (0=Sunday, 1=Monday).
showWeekNumberbooleanfalseShow week numbers in the calendar.
fixedWeeksbooleanfalseAlways show 6 weeks in the calendar.
closeOnSelectbooleantrueClose popover automatically when a complete range is selected.
urlParamKeystring-URL search param key for syncing date range to URL.
urlFormat"iso" | "timestamp""iso"Format for serializing dates in URL.
onUrlChange(url: string) => void-Callback when URL should be updated (use with router.push).
namestring-Form field name for hidden input.
requiredboolean-Whether the field is required for form submission.
isDisabledbooleanfalseWhether the date range picker is disabled.
children*ReactNode-The trigger element and popover content.

DateRangePickerTrigger Props

PropTypeDefaultDescription
children*ReactElement-The trigger element (usually a Button).
...propsPopoverTriggerProps-All PopoverTrigger props are supported.

DateRangePickerNavigation Props

PropTypeDefaultDescription
hidePreviousboolean-Hide the previous month selection button.
hideNextboolean-Hide the next month selection button.
...propsdiv-All standard div props are supported. Note: Clicking navigation buttons selects the full previous/next month as the date range.

DateRangePickerContent Props

PropTypeDefaultDescription
showPresetsbooleanfalseShow the presets sidebar automatically.
...propsPopoverContentProps-All PopoverContent props are supported.

DateRangePickerActions Props

PropTypeDefaultDescription
showClearbooleantrueShow the clear button.
showCancelbooleantrueShow the cancel button.
showApplybooleantrueShow the apply button.
clearLabelstring"Clear"Label for the clear button.
cancelLabelstring"Cancel"Label for the cancel button.
applyLabelstring"Apply"Label for the apply button.
onApply() => void-Callback when apply button is clicked.

Sub-components

The following sub-components are available for customizing the date range picker interface:

  • DateRangePickerTrigger - Button that opens the popover
  • DateRangePickerNavigation - External chevron arrows that select full previous/next month
  • DateRangePickerContent - Popover content wrapper
  • DateRangePickerPresets - Preset buttons sidebar
  • DateRangePickerCalendar - Dual-month calendar with internal navigation
  • DateRangePickerDisplay - Formatted date range text
  • DateRangePickerActions - Footer with Clear/Cancel/Apply buttons

Utility Functions

Helper functions for common operations:

  • getLocalizedPresets(localeCode) - Get preset labels in specified language (en, de, fr, es)
  • serializeDateRange(range, format) - Serialize date range for URL
  • parseDateRangeFromSearchParams(param) - Parse date range from URL string
  • buildDateRangeUrl(baseUrl, key, range) - Build URL with date range param
  • useDateRangePicker() - Hook to access context within sub-components

Source Code

Loading...