Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: ensure full year range is visible in reminder dialog's day picker (#9928)

01zulficd071f8f5830
diff --git a/apps/web/src/components/day-picker/index.tsx b/apps/web/src/components/day-picker/index.tsx
index 6253a1d3d..72f5812b5 100644
--- a/apps/web/src/components/day-picker/index.tsx
+++ b/apps/web/src/components/day-picker/index.tsx
@@ -46,7 +46,21 @@ export function DayPicker(props: DayPickerProps) {
maxDate,
minDate
},
- years: { numberOfYears: 99 },
+ years: {
+ /**
+ * When minDate and maxDate are provided, we switch to "fluid" mode and calculate the number of years in a way that all valid years are visible.
+ *
+ * When not provided, use default mode and numberOfYears.
+ */
+ numberOfYears:
+ minDate && maxDate
+ ? Math.max(
+ Math.abs(maxDate.getFullYear() - selected.getFullYear()) + 1,
+ Math.abs(selected.getFullYear() - minDate.getFullYear()) + 1
+ ) * 2
+ : 99,
+ mode: minDate && maxDate ? "fluid" : "decade"
+ },
calendar: {
startDay: 0
}
@@ -86,7 +100,10 @@ export function DayPicker(props: DayPickerProps) {
<Button
variant="icon"
sx={{ p: 0 }}
- {...subtractOffset({ months: 1 }, { disabled: isPrevMonthBeforeMin })}
+ {...subtractOffset(
+ { months: 1 },
+ { disabled: isPrevMonthBeforeMin }
+ )}
>
<ChevronLeft />
</Button>