πΈ Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Fix date picker calendar highlighting a different range than the draft (#1307)
Goldflagb8b17832fc54
diff --git a/client/src/components/DateSelector/RangePanel.test.tsx b/client/src/components/DateSelector/RangePanel.test.tsxindex f760ec507..b7064edfe 100644--- a/client/src/components/DateSelector/RangePanel.test.tsx+++ b/client/src/components/DateSelector/RangePanel.test.tsx@@ -248,6 +248,32 @@ describe("RangePanel draft", () => {expect(screen.getByLabelText<HTMLInputElement>("End date").value).toBe("2024-03-20");});+ it("highlights the drafted range on the calendar, not react-day-picker's own guess", () => {+ renderPanel(DATE_RANGE);++ // react-day-picker's own range mode would extend 3/8β3/14 to 3/8β3/20 here+ fireEvent.click(day("3/20/2024"));+ expect(day("3/20/2024").dataset.rangeStart).toBe("true");+ expect(day("3/20/2024").dataset.rangeEnd).toBe("true");+ expect(day("3/8/2024").closest("[data-selected]")).toBeNull();++ // ...and then shrink that to 3/8β3/18 instead of drawing 3/18β3/20+ fireEvent.click(day("3/18/2024"));+ expect(day("3/18/2024").dataset.rangeStart).toBe("true");+ expect(day("3/19/2024").dataset.rangeMiddle).toBe("true");+ expect(day("3/20/2024").dataset.rangeEnd).toBe("true");+ expect(day("3/8/2024").closest("[data-selected]")).toBeNull();+ });++ it("follows a typed date on the calendar", () => {+ renderPanel(DATE_RANGE);++ fireEvent.change(screen.getByLabelText("End date"), { target: { value: "2024-03-11" } });++ expect(day("3/11/2024").dataset.rangeEnd).toBe("true");+ expect(day("3/14/2024").closest("[data-selected]")).toBeNull();+ });+it("one click is a single day, which is what gets an hourly bucket", () => {renderPanel(DATE_RANGE);diff --git a/client/src/components/DateSelector/RangePanel.tsx b/client/src/components/DateSelector/RangePanel.tsxindex 6d8414d93..74c8486e1 100644--- a/client/src/components/DateSelector/RangePanel.tsx+++ b/client/src/components/DateSelector/RangePanel.tsx@@ -254,11 +254,14 @@ export function RangePanel({// it is read again once the breakpoint is known.key={months}mode="range"+ // Passing `onSelect` is what makes `selected` controlled. Without it+ // react-day-picker copies `selected` once on mount and then runs its+ // own range logic on every click, so the highlighting drifted away+ // from the draft that the bound fields (and Apply) actually read.+ // The range it proposes is ignored: `pickDay` owns the two-click+ // sequence. Disabled days never reach this.selected={selected}- onDayClick={(date, modifiers) => {- if (modifiers.disabled) return;- pickDay(fromCalendarDate(date));- }}+ onSelect={(_range, triggerDate) => pickDay(fromCalendarDate(triggerDate))}defaultMonth={(selected?.to ? DateTime.fromJSDate(selected.to).startOf("month") : lastMonth).minus({ months: months - 1 }).toJSDate()}