From 76ad5621c6ac5f171e28002f25639383f6497a37 Mon Sep 17 00:00:00 2001 From: Lebaud Antoine Date: Wed, 14 Jun 2023 14:02:40 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(react)=20fix=20calendar=20selects?= =?UTF-8?q?=20initialization=20and=20syncing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Select under the calendar component were not properly initialized, leading to issues. Additionally, syncing the dropdowns with the calendar state was causing unnecessary renders. Selects now update on user events triggered by the toggle button, ensuring the selected item remains up-to-date. The code has been refactored to eliminate duplication and improve the component's readability and maintainability. --- .changeset/strange-jeans-confess.md | 5 + .../components/Forms/DatePicker/Calendar.tsx | 97 ++++++++----------- 2 files changed, 45 insertions(+), 57 deletions(-) create mode 100644 .changeset/strange-jeans-confess.md diff --git a/.changeset/strange-jeans-confess.md b/.changeset/strange-jeans-confess.md new file mode 100644 index 0000000..95e7a94 --- /dev/null +++ b/.changeset/strange-jeans-confess.md @@ -0,0 +1,5 @@ +--- +"@openfun/cunningham-react": patch +--- + +Fix initial focused item on select opening under the calendar diff --git a/packages/react/src/components/Forms/DatePicker/Calendar.tsx b/packages/react/src/components/Forms/DatePicker/Calendar.tsx index 4372ce3..66d2cb9 100644 --- a/packages/react/src/components/Forms/DatePicker/Calendar.tsx +++ b/packages/react/src/components/Forms/DatePicker/Calendar.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useMemo, useRef } from "react"; +import React, { useMemo, useRef } from "react"; import { CalendarDate, createCalendar, @@ -127,17 +127,6 @@ export const Calendar = ({ }); }, [state.maxValue, state.minValue, state.focusedDate.year]); - const downshiftMonth = useSelect({ - items: monthItems, - itemToString: optionToString, - onSelectedItemChange: (e: UseSelectStateChange