From 308eb7d95a7cf13a0b08b90bce9a103cdff6c35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Oliver=20S=C3=B8berg?= Date: Thu, 31 Aug 2023 18:59:25 +0200 Subject: [PATCH 1/2] Fix month comparison, dont respect day of month when comparing months --- .../core/react/src/date/monthpicker/MonthButton.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/@navikt/core/react/src/date/monthpicker/MonthButton.tsx b/@navikt/core/react/src/date/monthpicker/MonthButton.tsx index b7ddf8bbb5..8aace9817d 100644 --- a/@navikt/core/react/src/date/monthpicker/MonthButton.tsx +++ b/@navikt/core/react/src/date/monthpicker/MonthButton.tsx @@ -1,8 +1,7 @@ import cl from "clsx"; -import compareAsc from "date-fns/compareAsc"; -import compareDesc from "date-fns/compareDesc"; import format from "date-fns/format"; import isSameMonth from "date-fns/isSameMonth"; +import isSameYear from "date-fns/isSameYear"; import setYear from "date-fns/setYear"; import React, { useEffect, useRef } from "react"; import { useDayPicker } from "react-day-picker"; @@ -20,13 +19,12 @@ interface MonthType { const disableMonth = (month: Date, fromDate?: Date, toDate?: Date) => { if (fromDate && toDate) { - return ( - compareAsc(month, fromDate) === -1 || compareDesc(month, toDate) === -1 - ); + return (isSameMonth(month, fromDate) && isSameYear(month, fromDate)) + || (isSameMonth(month, toDate) && isSameYear(month, toDate)) } else if (fromDate) { - return compareAsc(month, fromDate) === -1; + return isSameMonth(month, fromDate) && isSameYear(month, fromDate) } else if (toDate) { - return compareDesc(month, toDate) === -1; + return isSameMonth(month, toDate) && isSameYear(month, toDate) } return false; }; From 6305d05e800c54e76445175ebf9918c270448f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Oliver=20S=C3=B8berg?= Date: Thu, 31 Aug 2023 19:12:24 +0200 Subject: [PATCH 2/2] Patch bump ds-react changeset --- .changeset/eleven-pumas-jog.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/eleven-pumas-jog.md diff --git a/.changeset/eleven-pumas-jog.md b/.changeset/eleven-pumas-jog.md new file mode 100644 index 0000000000..16271d77a4 --- /dev/null +++ b/.changeset/eleven-pumas-jog.md @@ -0,0 +1,5 @@ +--- +"@navikt/ds-react": patch +--- + +Fix bug in monthpicker, only compare year and month for equality on date object