Registry / web-framework / react-day-picker

react-day-picker

JSON →
library9.14.0jsnpmunverified

React DayPicker is a highly customizable and accessible date picker component for React applications, currently at version 9.14.0. It offers extensive features for single, multiple, and range date selections, along with advanced localization capabilities supporting various calendar systems including ISO 8601, Persian, Hijri, Buddhist, Ethiopic, and Hebrew. The library is actively maintained with frequent minor and patch releases, indicating ongoing development and improvements. Key differentiators include its focus on accessibility (WCAG 2.1 AA compliant), flexible styling with CSS, robust timezone handling, and a modular architecture that allows for custom components and extensions. It ships with TypeScript types and is compiled to both CommonJS and ESM, making it suitable for modern React projects.

npm install react-day-picker
INSTALL
IMPORT
SIG · REACT-DAY-PICKER
R
react-day-picker
web-frameworkjavascriptv9.14.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DayPicker
import { DayPicker } from 'react-day-picker';
const DayPicker = require('react-day-picker');
Primary component import. For CommonJS, `require('react-day-picker')` directly is typically fine in modern Node.js environments, but `import` is preferred for ESM.
styles
import 'react-day-picker/dist/style.css';
import 'react-day-picker/lib/style.css';
CSS styles must be imported separately. The path changed from `lib/style.css` to `dist/style.css` in v8.
es (locale)
import { es } from 'react-day-picker/locale';
import { es } from 'react-day-picker';
Locales are imported from the `/locale` subpath since v9.12.0 and now include translated labels by default.
DayPicker (Hijri calendar)
import { DayPicker } from 'react-day-picker/hijri';
Specialized calendar systems (like Hijri, Buddhist, Ethiopic, Persian, Hebrew) are imported from their respective subpaths.

This quickstart demonstrates a basic single-date selection DayPicker component with localization, year/month dropdowns, a footer displaying the selected date, and custom styling. It shows how to import the component, its styles, and a locale, and manage the selected state using React hooks.

import React, { useState } from 'react'; import { DayPicker } from 'react-day-picker'; import { enUS } from 'react-day-picker/locale'; import 'react-day-picker/dist/style.css'; interface MyDatePickerProps { initialDate?: Date; } export function MyDatePicker({ initialDate }: MyDatePickerProps) { const [selectedDate, setSelectedDate] = useState<Date | undefined>(initialDate); const handleDaySelect = (date: Date | undefined) => { setSelectedDate(date); }; return ( <div className="my-day-picker-container"> <h3>Select a Date</h3> <DayPicker mode="single" selected={selectedDate} onSelect={handleDaySelect} locale={enUS} captionLayout="dropdown" fromYear={2000} toYear={2030} footer={ selectedDate ? `<p>You selected ${selectedDate.toLocaleDateString()}</p>` : '<p>Please pick a day.</p>' } /> <style jsx global>{` .my-day-picker-container { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; max-width: 300px; margin: 20px auto; padding: 15px; border: 1px solid #e0e0e0; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); } .my-day-picker-container h3 { text-align: center; margin-bottom: 20px; color: #333; } .my-day-picker-container p { text-align: center; color: #555; margin-top: 15px; font-size: 0.9em; } .rdp { --rdp-cell-size: 36px; --rdp-background-color: #f7f7f7; --rdp-accent-color: #007bff; --rdp-selected-color: #fff; --rdp-today-color: #007bff; --rdp-caption-color: #333; --rdp-nav-button-color: #666; --rdp-border-radius: 4px; } `}</style> </div> ); }
Debug
Known issues
breakingThe default grid markup and class names for UI elements changed in v9.11.3, potentially affecting brittle snapshot tests or custom CSS rules that relied on the previous structure. For example, `day_disabled` is now `disabled`, `cell` is now `day`, and `day` is `day_button`.
fix
Update custom CSS classes and snapshot tests to reflect the new markup and class names. Refer to the v9 upgrade guide for a full list of renamed classes and components.
affects: >=9.11.3
gotchaSince v9.12.0, built-in locales (e.g., `es`, `enUS`) now ship with translated labels for elements like 'Go to next month' or 'Today'. If you were previously providing these translations via the `labels` prop, you might find redundant labels or unexpected behavior.
fix
Remove the `labels` prop when using a built-in locale, as it now includes default translations. Only use `labels` for custom translations or non-standard locales.
affects: >=9.12.0
breakingThe `DayPickerInput` component has been entirely removed in v8. Upgrading from v7 or earlier requires a complete rewrite of any input-field integrations, typically by using a controlled `DayPicker` component in conjunction with a custom input field.
fix
Migrate from `DayPickerInput` by implementing a custom input field that manages the date state and interacts with `DayPicker` via its `selected` and `onSelect` props. Refer to the 'Input Fields Guide' in the documentation.
affects: >=8.0.0
breakingMany prop names were changed in v8 (e.g., `showWeekNumbers` to `showWeekNumber`, `initialMonth` to `defaultMonth`, `selectedDays` to `selected`, `disabledDays` to `disabled`). If upgrading from v7, these changes will break existing implementations.
fix
Consult the v8 upgrade guide and update all changed prop names in your `DayPicker` components.
affects: >=8.0.0
breakingThe `date-fns` library became a peer dependency starting from v8. While `react-day-picker` previously relied on it internally, it's now explicitly required for proper functioning, and users need to install it alongside the package.
fix
Install `date-fns` as a dependency: `npm install date-fns` or `yarn add date-fns`. If you were not using `date-fns` directly, you might have removed it in previous upgrades, so ensure it's present.
affects: >=8.0.0
gotchaWhen using `DayPicker` in range selection mode and a full range is already selected, subsequent clicks would typically extend the existing range. The `resetOnSelect` prop was introduced in v9.14.0 to change this behavior and start a new range.
fix
If you desire to start a new range when a full range is already selected in range mode, add the `resetOnSelect` prop to your `DayPicker` component: `<DayPicker mode="range" resetOnSelect />`.
affects: >=9.14.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'DayPicker') OR DayPicker is not a function
Attempting to use CommonJS `require` syntax with a package that primarily targets ES Modules or when the default export is not correctly accessed.
fix
Ensure you are using ES Module imports: `import { DayPicker } from 'react-day-picker';`. If server-side rendering with CommonJS, ensure your build setup correctly handles ESM or use a dynamic `import()` statement if supported by your runtime. While `react-day-picker` compiles to CommonJS, ES module imports are the recommended modern approach.
DayPicker styles are not applied or look broken.
The default CSS stylesheet was not imported or the import path is incorrect, or custom CSS is overriding default styles unintentionally.
fix
Ensure you have `import 'react-day-picker/dist/style.css';` in your entry file or a relevant component. If upgrading from v7, note the path changed from `lib/style.css` to `dist/style.css`. Review custom CSS for conflicts.
My custom input field loses focus when selecting a day from the DayPicker.
When integrating DayPicker with a custom input (especially after `DayPickerInput` was removed), the focus might not persist on the input after a selection due to React's re-rendering.
fix
Implement a ref on your custom input and explicitly call `focus()` on the input's ref within the `onSelect` handler, potentially after updating the state. Pass the ref correctly to the underlying input element.
The `selected` prop doesn't seem to update the calendar or change the selected date.
Starting from v9, `selected` became a controlled prop. If `selected` is provided, `onSelect` must also be provided to handle state updates.
fix
When using the `selected` prop, always pair it with an `onSelect` prop to manage the state. For example: `const [selected, setSelected] = useState<Date>(); return <DayPicker selected={selected} onSelect={setSelected} />`.
Upgrade
Version history
9.14.0latest on npm
Audit
Dependencies
reactrequiredPeer dependency for React applications.
date-fnsrequiredPeer dependency for date manipulation and formatting. Required for full functionality.
Agent activity
2 hits · last 30 days
node
2
Resources
react-day-picker — npm install react-day-picker · libregistry