Skip to content

Month range picker #1610

Answered by gpbl
nandita1 asked this question in Support
Discussion options

You must be logged in to vote

@nandita1 here an example of a DayPicker selecting the whole month. Not the best UX, DayPicker maybe not the best component for you:

https://codesandbox.io/s/react-day-picker-select-month-gzztg1

import React, { useState } from "react";

import { isSameMonth } from "date-fns";
import { DayClickEventHandler, DayPicker } from "react-day-picker";

export default function App() {
  const [selectedMonths, setSelectedMonths] = useState<Date[]>([]);

  const handleDayClick: DayClickEventHandler = (day, modifiers) => {
    const newSelectedMonths = [...selectedMonths];
    if (modifiers.selected) {
      const index = selectedMonths.findIndex((selectedMonth) =>
        isSameMonth(day, selectedMonth)

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by gpbl
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants