Home page
Edit code

Interaction with disabled days

Modifiers are passed to event handlers. Here we use the disabled modifier to prevent selecting a disabled day.

import React from 'react';
import DayPicker from 'react-day-picker';

import 'react-day-picker/lib/style.css';

export default class Example extends React.Component {
  state = {
    selectedDay: null,
  };
  handleDayClick = (day, { disabled, selected }) => {
    if (disabled) {
      return;
    }
    this.setState({
      selectedDay: selected ? null : day,
    });
  };
  render() {
    const disabledDays = {
      daysOfWeek: [0, 6],
    };
    return (
      <div>
        <DayPicker
          enableOutsideDays
          selectedDays={this.state.selectedDay}
          disabledDays={disabledDays}
          onDayClick={this.handleDayClick}
        />
        <p>
          {this.state.selectedDay
            ? this.state.selectedDay.toLocaleDateString()
            : 'Please select a day 👻'}
        </p>
      </div>
    );
  }
}