Skip to content

Commit

Permalink
X2-9733 | Make a Purchase Date Picker Month Dropdown Closes Intermitt… (
Browse files Browse the repository at this point in the history
#329)

* X2-9733 | Make a Purchase Date Picker Month Dropdown Closes Intermittently

* linting and comment
  • Loading branch information
VitalyDevico authored May 14, 2024
1 parent 8126816 commit 250860d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/components/DatePicker/DatePicker.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import clsx from "clsx";
import dayjs from "dayjs";
import PropTypes from "prop-types";
import React, { useEffect, useState } from "react";
import React, { useEffect, useMemo, useState } from "react";
import DayPicker, { DateUtils } from "react-day-picker";
import "react-day-picker/lib/style.css";
import "./DatePicker.css";
import { isArray, isFunction } from "lodash";
import { Tooltip } from "../..";
import { now, isSame, toDate, isValidTimeZoneName } from "../../helpers/date";
import { isSame, isValidTimeZoneName, now, toDate } from "../../helpers/date";
import { Day } from "./Day";
import { MonthYearSelector } from "./MonthYearSelector";
import { RelativeDateRange } from "./RelativeDateRange";
import { NavbarElement } from "./NavbarElement";
import RangeDatePicker from "./RangeDatePicker";
import { RelativeDateRange } from "./RelativeDateRange";
import { UpcomingDatePicker } from "./UpcomingDatePicker";
import { NavbarElement } from "./NavbarElement";

const variants = {
single: "single",
Expand Down Expand Up @@ -158,10 +158,13 @@ export const DatePicker = ({
};

// TODO: Should be outside this component because this returns JSX
const CaptionElement =
shouldShowYearPicker && currentMonth
const CaptionElement = useMemo(() => {
return shouldShowYearPicker && currentMonth
? ({ date }) => <MonthYearSelector date={date} currentMonth={currentMonth} onChange={handleMonthChange} />
: undefined;
// Adding `handleMonthChange` causes a lot of re-renders, and closes drop-down.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [shouldShowYearPicker, currentMonth]);

// TODO: Should be outside this component because this returns JSX
const renderDay = (date) => {
Expand Down

0 comments on commit 250860d

Please sign in to comment.