Skip to content

DateRangePicker: add ability for predefined ranges #608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

hoorayimhelping
Copy link
Collaborator

@hoorayimhelping hoorayimhelping commented Jun 9, 2025

Adds predefined ranges to DateRangePicker.

  • allows setting predefined dates
  • allows limiting the range of dates to a specified value: maxRangeLength
  • allows setting a flag futureStartDatesDisabled, to disable start dates in the future

predefined dates list

Screenshot 2025-08-01 at 2 37 32 PM

limit of 15 for dateRangeLimit

Screenshot 2025-08-01 at 2 36 32 PM

Copy link

vercel bot commented Jun 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
click-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 8, 2025 7:56pm

@crisalbu
Copy link

Hey @hoorayimhelping , sorry for the late reply.

I was wondering, could we do this instead? I realize you may need to make more than a simple change, but it would look better I think 🙂

Screenshot 2025-06-16 at 15 02 38

Copy link

@crisalbu crisalbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work as always, @hoorayimhelping ! 🙌🏻

ariser
ariser previously requested changes Aug 1, 2025
Copy link
Collaborator

@ariser ariser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work @hoorayimhelping!
a few comments

Comment on lines +27 to +31
for (let i = 0; i < Math.abs(numberOfMonths); i++) {
const date = now.subtract(i, "month");
if (date.date() === 1 && date.month() === now.month()) {
continue;
}
Copy link
Collaborator

@ariser ariser Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something is off here
“last 6 months” actually displays last 5 months:
image

It might be just the naming of the story. But I feel like passing "-6" into the helper should return 6 items.

We either want to iterate until <= for past months, or not exclude the current month

it's actually an interesting question. But it seems to me that including the current month is the more expected option. Think “Show last 6 months of billing data” — I would expect to see whatever part of the current month has already passed as well

Copy link
Collaborator

@ariser ariser Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it seems to me that including the current month is the more expected option. Think “Show last 6 months of billing data” — I would expect to see whatever part of the current month has already passed as well

found a potential conflict: pasing -1 will return the same result as passing 1 then
(the same edge case also applies to the current imnplementation: passing -1 would return an empty result, which is weird)

so I'm changing my mind
I feel like

  • getPredefinedMonthsByNumber(1) should return the next month
  • getPredefinedMonthsByNumber(-1) should return the previous month
  • getPredefinedMonthsByNumber(0) should return nothing
  • getPredefinedMonthsByNumber should accept a 2nd argument with configuration, that should have a includeCurrentMonth: boolean
    • it can be true by default, then getPredefinedMonthsByNumber(0) will return the current month

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found a potential conflict: pasing -1 will return the same result as passing 1 then

Yeah, these are good points. I need to think over this a little deeper

something is off here “last 6 months” actually displays last 5 months...

That is an edge case around the first day of the month to avoid having a range where the start date is the same as the end date, namely the first day of the month (Aug 01, 2025 - Aug 01, 2025)

Copy link
Collaborator

@ariser ariser Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is an edge case around the first day of the month to avoid having a range where the start date is the same as the end date, namely the first day of the month (Aug 01, 2025 - Aug 01, 2025)

oh, I just realized it works like that
A few thoughts. And I found a bug.

  • if it's a single day, can't we display it simply as Aug 01, 2025?
  • We have props futureDatesDisabled and futureStartDatesDisabled
    • first the bug: you can still select future dates from the predefined list with these props set to true (which you shouldn't)
    • then the thought: I feel like these props should affect how getPredefinedMonthsByNumber behaves. It should always return the whole month with them being false.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with maxRangeLength, predefined dates can exceed this range, and still be selected
I guess it doesn't make sense to have predefined dates that don't match maxRangeLength at the same component, but we don't even warn about it

);
})}
</ScrollableContainer>
<StyledDropdownItem onClick={handleCustomTimePeriodClick}>
Copy link
Collaborator

@ariser ariser Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we show the calendar on hover?
less clicks
plus in general, I feel like I expect nested items in a dropdown to appear on hover rather than on click
cc @crisalbu

)}
</PredefinedCalendarContainer>
) : (
<CalendarRenderer calendarOptions={calendarOptions}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: this can be a variable, perhaps in a useMemo(), to avoid repeating all the props in two places

@ariser ariser dismissed their stale review August 8, 2025 11:44

Going on PTO next week, so I'll dismiss my request to unblock you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants