api

API Reference v8.10.0

Enumerations

EnumerationDescription
InternalModifierThe name of the modifiers that are used internally by DayPicker.

Interfaces

InterfaceDescription
CaptionLabelPropsThe props for the CaptionLabel component.
CaptionPropsRepresent the props of the Caption component.
CustomComponentsMap of the components that can be changed using the components prop.
DayContentPropsRepresent the props for the DayContent component.
DayPickerBaseThe base props for the DayPicker component and the DayPickerContext.
DayPickerContextValueThe value of the DayPickerContext extends the props from DayPicker
with default and cleaned up values.
DayPickerDefaultPropsThe props for the DayPicker component when using mode="default" or undefined.
DayPickerMultiplePropsThe props for the DayPicker component when using mode="multiple".
DayPickerProviderPropsThe props for the DayPickerProvider.
DayPickerRangePropsThe props for the DayPicker component when using mode="range".
DayPickerSinglePropsThe props for the DayPicker component when using mode="single".
DayPropsRepresent the props used by the Day component.
DropdownPropsThe props for the Dropdown component.
FooterProps-
NavigationContextValueRepresents the value of the NavigationContext.
RootContextThe props of RootProvider.
RowPropsThe props for the Row component.
SelectMultipleContextValueRepresents the value of a SelectMultipleContext.
SelectRangeContextValueRepresents the value of a SelectRangeContext.
SelectRangeProviderProps-
SelectSingleContextValueRepresents the value of a SelectSingleContext.
SelectSingleProviderProps-
UseInputOptions-
UseInputValueRepresent the value returned by useInput.
WeekNumberPropsThe props for the WeekNumber component.

Type Aliases

Type aliasDescription
ActiveModifiersThe modifiers that are matching a day in the calendar. Use the useActiveModifiers hook to get the modifiers for a day.

const activeModifiers: ActiveModifiers = { selected: true, customModifier: true }
ButtonPropsThe props for the Button component.
CaptionLayoutThe layout of the caption:

- dropdown: display dropdowns for choosing the month and the year.
- buttons: display previous month / next month buttons.
- dropdown-buttons: display both month / year dropdowns and previous month / next month buttons.
ClassNamesThe class names of each element.
CustomModifiersA map of matchers used as custom modifiers by DayPicker component. This is
the same as []], but it accepts only array of [Matchers.
DateAfterA matcher to match a day falling after the specified date, with the date not included.
DateBeforeA matcher to match a day falling before the specified date, with the date not included.
DateFormatter-
DateIntervalA matcher to match a day falling before and/or after two dates, where the dates are not included.
DateRangeA matcher to match a range of dates. The range can be open. Differently from DateInterval, the dates here are included.
DayClickEventHandler-
DayFocusEventHandler-
DayKeyboardEventHandler-
DayLabel-
DayModifiersThe custom modifiers passed to the DayPickerBase.modifiers.
DayMouseEventHandler-
DayOfWeekA matcher to match a date being one of the specified days of the week (0-6, where 0 is Sunday).
DayPickerProps-
DayPointerEventHandler-
DayRender-
DaySelectionModeSelection modes supported by DayPicker.

- single: use DayPicker to select single days.
- multiple: allow selecting multiple days.
- range: use DayPicker to select a range of days
- default: disable the built-in selection behavior. Customize what is
selected by using DayPickerBase.onDayClick.
DayTouchEventHandler-
FocusContextValueRepresents the value of the FocusContext.
FocusProviderProps-
FormattersRepresent a map of formatters used to render localized content.
InputDayPickerPropsThe props to attach to the DayPicker component when using useInput.
InputPropsThe props to attach to the input field when using useInput.
InternalModifiersMap of matchers used for the internal modifiers.
InternalModifiersElementThese elements must not be in the styles or classNames records as they are styled via the modifiersStyles or modifiersClassNames pop
LabelsMap of functions to translate ARIA labels for the relative elements.
MatcherA value or a function that matches a specific day.


Matchers are passed to DayPicker via DayPickerBase.disabled,
[]] or [DayPickerProps.selected and are used to
determine if a day should get a Modifier.

Matchers can be of different types:

// will always match the day const booleanMatcher: Matcher = true; // will match the today's date const dateMatcher: Matcher = new Date(); // will match the days in the array const arrayMatcher: Matcher = [new Date(2019, 1, 2), new Date(2019, 1, 4)]; // will match days after the 2nd of February 2019 const afterMatcher: DateAfter = { after: new Date(2019, 1, 2) }; // will match days before the 2nd of February 2019 } const beforeMatcher: DateBefore = { before: new Date(2019, 1, 2) }; // will match Sundays const dayOfWeekMatcher: DayOfWeek = { dayOfWeek: 0 }; // will match the included days, except the two dates const intervalMatcher: DateInterval = { after: new Date(2019, 1, 2), before: new Date(2019, 1, 5) }; // will match the included days, including the two dates const rangeMatcher: DateRange = { from: new Date(2019, 1, 2), to: new Date(2019, 1, 5) }; // will match when the function return true const functionMatcher: Matcher = (day: Date) => { return day.getMonth() === 2 // match when month is March };
ModifierA modifier represents different styles or states of a day displayed in the calendar.
ModifiersThe modifiers used by DayPicker.
ModifiersClassNamesThe classnames to assign to each day element matching a modifier.
ModifiersStylesThe style to apply to each day element matching a modifier.
MonthChangeEventHandler-
MonthsPropsThe props for the Months component.
NavButtonLabel-
SelectMultipleEventHandler-
SelectMultipleModifiersRepresent the modifiers that are changed by the multiple selection.
SelectMultipleProviderProps-
SelectRangeEventHandler-
SelectRangeModifiersRepresent the modifiers that are changed by the range selection.
SelectSingleEventHandler-
StyledComponentProps of a component that can be styled via classNames or inline-styles.
StyledElementThe style (either via class names or via in-line styles) of an element.
StylesThe inline-styles of each styled element, to use with the styles prop. Day
modifiers, such as today or hidden, should be styled using the
modifiersStyles prop.
WeekNumberClickEventHandler-
WeekNumberFormatter-
WeekNumberLabel-
WeekdayLabel-

Variables

VariableDescription
DayPickerContextThe DayPicker context shares the props passed to DayPicker within internal
and custom components. It is used to set the default values and perform
one-time calculations required to render the days.

Access to this context from the useDayPicker hook.
FocusContextThe Focus context shares details about the focused day for the keyboard

Access this context from the useFocusContext hook.
NavigationContextThe Navigation context shares details and methods to navigate the months in DayPicker.
Access this context from the useNavigation hook.
SelectMultipleContextThe SelectMultiple context shares details about the selected days when in
multiple selection mode.

Access this context from the useSelectMultiple hook.
SelectRangeContextThe SelectRange context shares details about the selected days when in
range selection mode.

Access this context from the useSelectRange hook.
SelectSingleContextThe SelectSingle context shares details about the selected days when in
single selection mode.

Access this context from the useSelectSingle hook.

Functions

FunctionDescription
ButtonRender a button HTML element applying the reset class name.
CaptionRender the caption of a month. The caption has a different layout when
setting the DayPickerBase.captionLayout prop.
CaptionDropdownsRender a caption with the dropdowns to navigate between months and years.
CaptionLabelRender the caption for the displayed month. This component is used when captionLayout="buttons".
CaptionNavigationRender a caption with a button-based navigation.
DayThe content of a day cell – as a button or span element according to its
modifiers.
DayContentRender the content of the day cell.
DayPickerDayPicker render a date picker component to let users pick dates from a
calendar. See http://react-day-picker.js.org for updated documentation and
examples.

### Customization

DayPicker offers different customization props. For example,

- show multiple months using numberOfMonths
- display a dropdown to navigate the months via captionLayout
- display the week numbers with showWeekNumbers
- disable or hide days with disabled or hidden

### Controlling the months

Change the initially displayed month using the defaultMonth prop. The
displayed months are controlled by DayPicker and stored in its internal
state. To control the months yourself, use month instead of defaultMonth
and use the onMonthChange event to set it.

To limit the months the user can navigate to, use
fromDate/fromMonth/fromYear or toDate/toMonth/toYear.

### Selection modes

DayPicker supports different selection mode that can be toggled using the
mode prop:

- mode="single": only one day can be selected. Use required to make the
selection required. Use the onSelect event handler to get the selected
days.
- mode="multiple": users can select one or more days. Limit the amount of
days that can be selected with the min or the max props.
- mode="range": users can select a range of days. Limit the amount of days
in the range with the min or the max props.
- mode="default" (default): the built-in selections are disabled. Implement
your own selection mode with onDayClick.

The selection modes should cover the most common use cases. In case you
need a more refined way of selecting days, use mode="default". Use the
selected props and add the day event handlers to add/remove days from the
selection.

### Modifiers

A modifier represents different styles or states for the days displayed in
the calendar (like "selected" or "disabled"). Define custom modifiers using
the modifiers prop.

### Formatters and custom component

You can customize how the content is displayed in the date picker by using
either the formatters or replacing the internal components.

For the most common cases you want to use the formatters prop to change how
the content is formatted in the calendar. Use the components prop to
replace the internal components, like the navigation icons.

### Styling

DayPicker comes with a default, basic style in react-day-picker/style – use
it as template for your own style.

If you are using CSS modules, pass the imported styles object the
classNames props.

You can also style the elements via inline styles using the styles prop.

### Form fields

If you need to bind the date picker to a form field, you can use the
useInput hooks for a basic behavior. See the useInput source as an
example to bind the date picker with form fields.

### Localization

To localize DayPicker, import the locale from date-fns package and use the
locale prop.

For example, to use Spanish locale:

import { es } from 'date-fns/locale'; <DayPicker locale={es} />
DayPickerProviderThe provider for the DayPickerContext, assigning the defaults from the
initial DayPicker props.
DropdownRender a styled select component – displaying a caption and a custom
drop-down icon.
FocusProviderThe provider for the FocusContext.
FooterRender the Footer component (empty as default).
HeadRender the table head.
HeadRowRender the HeadRow component - i.e. the table head row with the weekday names.
IconDropdownRender the icon in the styled drop-down.
IconLeftRender the "previous month" button in the navigation.
IconRightRender the "next month" button in the navigation.
MonthsRender the wrapper for the month grids.
NavigationProviderProvides the values for the NavigationContext.
RootProviderProvide the value for all the context providers.
RowRender a row in the calendar, with the days and the week number.
SelectMultipleProviderProvides the values for the SelectMultipleContext.
SelectMultipleProviderInternal-
SelectRangeProviderProvides the values for the SelectRangeProvider.
SelectRangeProviderInternal-
SelectSingleProviderProvides the values for the SelectSingleProvider.
SelectSingleProviderInternal-
WeekNumberRender the week number element. If onWeekNumberClick is passed to DayPicker, it
renders a button, otherwise a span element.
addToRangeAdd a day to an existing range.

The returned range takes in account the undefined values and if the added
day is already present in the range.
isDateAfterTypeReturns true if value is of type DateAfter.
isDateBeforeTypeReturns true if value is of type DateBefore.
isDateIntervalReturns true if matcher is of type DateInterval.
isDateRangeReturns true if value is a DateRange type.
isDayOfWeekTypeReturns true if value is a DayOfWeek type.
isDayPickerDefaultReturns true when the props are of type DayPickerDefaultProps.
isDayPickerMultipleReturns true when the props are of type DayPickerMultipleProps.
isDayPickerRangeReturns true when the props are of type DayPickerRangeProps.
isDayPickerSingleReturns true when the props are of type DayPickerSingleProps.
isMatchReturns whether a day matches against at least one of the given Matchers.

const day = new Date(2022, 5, 19); const matcher1: DateRange = { from: new Date(2021, 12, 21), to: new Date(2021, 12, 30) } const matcher2: DateRange = { from: new Date(2022, 5, 1), to: new Date(2022, 5, 23) } const isMatch(day, [matcher1, matcher2]); // true, since day is in the matcher1 range.
useActiveModifiersReturn the active modifiers for the specified day.

This hook is meant to be used inside internal or custom components.
useDayPickerHook to access the DayPickerContextValue.

Use the DayPicker context to access to the props passed to DayPicker inside
internal or custom components.
useDayRenderReturn props and data used to render the Day component.

Use this hook when creating a component to replace the built-in Day
component.
useFocusContextHook to access the FocusContextValue. Use this hook to handle the
focus state of the elements.

This hook is meant to be used inside internal or custom components.
useInputReturn props and setters for binding an input field to DayPicker.
useNavigationHook to access the NavigationContextValue. Use this hook to navigate
between months or years in DayPicker.

This hook is meant to be used inside internal or custom components.
useSelectMultipleHook to access the SelectMultipleContextValue.

This hook is meant to be used inside internal or custom components.
useSelectRangeHook to access the SelectRangeContextValue.

This hook is meant to be used inside internal or custom components.
useSelectSingleHook to access the SelectSingleContextValue.

This hook is meant to be used inside internal or custom components.