DateRangePicker

Data input

A period typed as two dates or picked from a calendar in a popover: <DateRangePicker.Root> (bind:value a { start, end } of DateValues, bind:open, minDays, maxDays, minValue, maxValue, numberOfMonths) holds a DateRangePicker.Label (which names it; use it instead of Field.Label), DateRangePicker.Inputs (one box with the start and end inputs and the calendar button) and a DateRangePicker.Content (the popover, which draws a range calendar). Inside a Field, its description and error describe it.

import { DateRangePicker } from '@limerdev/zest';
DateRangePicker for AI tools (llms.txt)
Use for
A period in a form where seeing the months helps: a report's dates, an absence, a project phase.
Don't
A single date: use DatePicker. A period people type: use DateRangeField.

Examples

Basic

Type the dates, or pick the first and last day in the calendar.

Report period

Props

Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that renders your own element, with props to spread on it).

DateRangePicker.Root

Prop Type Default Description
calendarLabel string – This label is exclusively used for accessibility, remaining hidden from the page. It's read by screen readers when the calendar is opened. The current month and year are automatically appended to the label, so you only need to provide the base label. For instance: - 'Date of birth' will be read as 'Date of birth, January 2021' if the current month is January 2021. - 'Appointment date' will be read as 'Appointment date, January 2021' if the current month is January 2021. - 'Booking date' will be read as 'Booking date, January 2021' if the current month is January 2021.
closeOnRangeSelect boolean true Whether to close the popover when a date range is selected.
disabled boolean false If true, the date field will be disabled and users will not be able to interact with it. This also disables the hidden input element if the date field is used in a form.
disableDaysOutsideMonth boolean false Whether to disable the selection of days outside the current month. By default, days outside the current month are rendered to fill the calendar grid, but they are not selectable. Setting this prop to true will disable this behavior.
errorMessageId string – The id of the element which contains the error messages for the date field when the date is invalid.
excludeDisabled boolean false Whether to automatically reset the range if any date within the selected range becomes disabled. When true, the entire range will be cleared if a disabled date is found between the start and end dates.
fixedWeeks boolean false Display 6 weeks per month, regardless the month's number of weeks. This is useful for displaying a consistent calendar, where the size of the calendar doesn't change month to month. To display 6 weeks per month, you will need to render out the previous and next month's dates in the calendar as well.
granularity "day" | "hour" | "minute" | "second" 'day' The granularity of the date field. This determines which segments will be includes in the segments array used to build the date field. By default, when a CalendarDate value is used, the granularity will default to 'day', and when a CalendarDateTime or ZonedDateTime value is used, the granularity will default to 'minute'. Granularity is only used for visual purposes, and does not impact the value of the date field. You can have the same value synced between multiple date fields with different granularities and they will all contain the same value.
hideTimeZone boolean false; Whether or not to hide the timeZoneName segment from the date field.
hourCycle 12 | 24 the locale's default time format The format to use for displaying the time in the input. If using a 12 hour clock, ensure you also include the dayPeriod segment in your input to ensure the user can select AM/PM.
isDateDisabled DateMatcher – A function that returns true if the given date is disabled, which makes the date unable to be selected in the calendar.
isDateUnavailable DateMatcher – A function that returns true if the given date is unavailable, where if selected, the date field will be marked as invalid.
locale string 'en' The locale to use for formatting the date field.
maxDays number undefined The maximum number of days that can be selected in a range.
maxValue DateValue – The maximum acceptable date. When provided, the date field will be marked as invalid if the user enters a date after this date.
minDays number undefined The minimum number of days that can be selected in a range.
minValue DateValue – The minimum acceptable date. When provided, the date field will be marked as invalid if the user enters a date before this date.
monthFormat "numeric" | "long" | "short" | "narrow" | "2-digit" | ((month: number) => string) "long" The format of the month names in the calendar.
numberOfMonths number 1 Determines the number of months to display on the calendar simultaneously. For navigation between months, refer to the pagedNavigation prop.
onEndValueChange OnChangeFn<DateValue | undefined> – A callback function called when the end value changes. This doesn't necessarily mean the value has updated and should be used to apply cosmetic changes to the calendar when only part of the value is changed/completed.
onInvalid DateOnInvalid – A callback fired when the date field's value is invalid. Use this to display an error message to the user.
onOpenChange OnChangeFn<boolean> – A callback function called when the open state changes.
onOpenChangeComplete OnChangeFn<boolean> – A callback function called when the open state changes complete.
onPlaceholderChange OnChangeFn<DateValue> – A callback function called when the placeholder value changes.
onStartValueChange OnChangeFn<DateValue | undefined> – A callback function called when the start value changes. This doesn't necessarily mean the value has updated and should be used to apply cosmetic changes to the calendar when only part of the value is changed/completed.
onValueChange OnChangeFn<DateRange> – A callback function called when the value changes.
open bindable boolean false The open state of the date picker popover.
pagedNavigation boolean false Applicable only when numberOfMonths is greater than 1. Controls whether to use paged navigation for the next and previous buttons in the date picker. With paged navigation set to true, clicking the next/prev buttons changes all months in view. When set to false, it shifts the view by a single month. For example, with pagedNavigation set to true and 2 months displayed (January and February), clicking the next button changes the view to March and April. If pagedNavigation is false, the view shifts to February and March.
placeholder bindable DateValue – The placeholder value of the date field. This determines the format and what date the field starts at when it is empty.
preventDeselect boolean false Whether or not users can deselect a date once selected without selecting another date.
readonly boolean false If true, the date field will be readonly, and users will not be able to edit the values of any of the individual segments.
readonlySegments ("month" | "year" | "day" | "hour" | "minute" | "second" | "dayPeriod")[] – An array of segment names that should be readonly. If provided, only the segments not in this array will be editable.
required boolean false Whether or not the hidden input of the date field requires a value to be submitted.
validate DateRangeValidator – A function that returns a string or array of strings as validation errors if the date is invalid, or nothing if the date is valid
value bindable DateRange – The value of the date picker.
weekdayFormat "long" | "short" | "narrow" 'short' How the string representation of the weekdays provided via the weekdays state store should be formatted. md - "long": "Sunday", "Monday", "Tuesday", etc. - "short": "Sun", "Mon", "Tue", etc. - "narrow": "S", "M", "T", etc.
weekStartsOn 0 | 1 | 2 | 3 | 4 | 5 | 6 0 (Sunday) The day of the week to start the calendar on, which must be a number between 0 and 6, where 0 is Sunday and 6 is Saturday.
yearFormat "numeric" | "2-digit" | ((year: number) => string) "numeric" The format of the year names in the calendar.

DateRangePicker.Label

No props of its own beyond the common ones.

DateRangePicker.Inputs

No props of its own beyond the common ones.

DateRangePicker.Input

Prop Type Default Description
name string – The name to use for the hidden input element associated with this input used for form submission.
type required "start" | "end" – Whether this input represents the start or end of the date range.

DateRangePicker.Segment

Prop Type Default Description
part required "month" | "year" | "day" | "hour" | "minute" | "second" | "dayPeriod" | "timeZoneName" | "literal" –

DateRangePicker.Trigger

Prop Type Default Description
closeDelay number 300 How long to wait before closing the popover after hover ends (ms). Only applies when openOnHover is true.
label string the Config's `strings.openCalendar`, else 'Open calendar' The button's name for screen readers.
openDelay number 700 How long to wait before opening the popover on hover (ms). Only applies when openOnHover is true.
openOnHover boolean false Whether the popover should open when the trigger is hovered.

DateRangePicker.Content

Prop Type Default Description
align "start" | "center" | "end" 'start' The preferred alignment of the anchor to render against when open. This may change when collisions occur.
alignOffset number – An offset in pixels from the "start" or "end" alignment options.
arrowPadding number – This describes the padding between the arrow and the edges of the floating element. If your floating element has border-radius, this will prevent it from overflowing the corners.
avoidCollisions boolean true When true, overrides the side and align options to prevent collisions with the boundary edges.
collisionBoundary Arrayable<Boundary> – A boundary element or array of elements to check for collisions against.
collisionPadding number | Partial<Record<"top" | "right" | "bottom" | "left", number>> 8 The amount in pixels of virtual padding around the viewport edges to check for overflow which will cause a collision.
customAnchor string | HTMLElement | Measurable | null – Use an element other than the trigger to anchor the content to. If provided, the content will be anchored to the provided element instead of the trigger. You can pass a selector string or an HTMLElement.
dir "ltr" | "rtl" – The text direction of the content.
escapeKeydownBehavior "close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore" close Escape behavior type. close: Closes the element immediately. defer-otherwise-close: Delegates the action to its parent component that has an escape keydown handler. If no parent is found, it closes the element. defer-otherwise-ignore: Delegates the action to the parent element. If no parent is found, nothing is done. ignore: Prevents the element from closing and also blocks the parent element from closing in response to an escape key press.
forceMount boolean – Whether to force mount the component.
hideWhenDetached boolean –
interactOutsideBehavior "close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore" close Interact outside behavior type. close: Closes the element immediately. defer-otherwise-close: Delegates the action to the parent element. If no parent is found, it closes the element. defer-otherwise-ignore: Delegates the action to the parent element. If no parent is found, nothing is done. ignore: Prevents the element from closing and also blocks the parent element from closing in response to an outside interaction.
onCloseAutoFocus EventCallback – Event handler called when auto-focusing on close. Can be prevented.
onEscapeKeydown ((e: KeyboardEvent) => void) – Callback fired when escape is pressed.
onFocusOutside ((event: FocusEvent) => void) – Callback fired when focus leaves the dismissible layer.
onInteractOutside InteractOutsideEventHandler – Callback fired when an outside interaction event completes, which is either a pointerup, mouseup, or touchend event, depending on the user's input device.
onOpenAutoFocus EventCallback – Event handler called when auto-focusing on open. Can be prevented.
portalProps PortalProps – Props for the portal the content renders in: to (the element to render in, the body by default) and disabled (render in place).
preventOverflowTextSelection boolean true Passing true will prevent the overflow of text selection outside the element, provided the element is the top layer.
preventScroll boolean true Whether to prevent scrolling the body when the content is open. Whether to prevent body scrolling when the content is open.
side "top" | "right" | "bottom" | "left" – The preferred side of the anchor to render against when open. Will be reversed when collisions occur.
sideOffset number 4 The distance in pixels from the anchor to the floating element.
sticky "partial" | "always" –
strategy "absolute" | "fixed" – The positioning strategy to use for the floating element.
trapFocus boolean false Whether focus is trapped within the focus scope.
updatePositionStrategy "always" | "optimized" "optimized" "optimized" will only update the position when necessary, while "always" will update the position on each animation frame, which is useful if the floating content is following something like a mouse cursor.

DateRangePicker.Portal

Prop Type Default Description
disabled boolean false Disable portalling and render the component inline
to PortalTarget document.body Where to portal the content to.

DateRangePicker.Calendar

No props of its own beyond the common ones.

DateRangePicker.Header

No props of its own beyond the common ones.

DateRangePicker.Heading

No props of its own beyond the common ones.

DateRangePicker.PrevButton

No props of its own beyond the common ones.

DateRangePicker.NextButton

No props of its own beyond the common ones.

DateRangePicker.Months

No props of its own beyond the common ones.

DateRangePicker.Grid

No props of its own beyond the common ones.

DateRangePicker.GridHead

No props of its own beyond the common ones.

DateRangePicker.GridBody

No props of its own beyond the common ones.

DateRangePicker.GridRow

No props of its own beyond the common ones.

DateRangePicker.HeadCell

No props of its own beyond the common ones.

DateRangePicker.Cell

Prop Type Default Description
date required DateValue – The date value of the cell.
month required DateValue – The month DateValue that this cell is being rendered in.

DateRangePicker.Day

No props of its own beyond the common ones.