React DayPicker

9.14.0 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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>
  );
}

view raw JSON →