Hacker0x01 / react-datepicker

A simple and reusable datepicker component for React

Home Page:https://reactdatepicker.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[feature proposal] "auto range" better UX for large ranges

mirus-ua opened this issue · comments

Is your feature request related to a problem? Please describe.
When you work with the range datepicker and your ranges are more than a month, the price of a mistake is high, so if you miss your endDate or startDate, you must redo everything from scratch. It means tedious scrolling back and forth through months to reselect the proper dates. I tried to visualize the pain in the video below.

2024-04-03.10.38.05.mov

Describe the solution you'd like
We may extend the Datepicker component with an optional prop autoRange (or suggest a better name for it) that will prevent nullifying the range but rather modify a start or an end date according to simple logic:

if (clickedDate < middleDateOfTheRange) {
  startDate = clickedDate
} else {
  endDate = clickedDate
}

I see only one drawback: the ability to reset the range in the default calendar.

Describe alternatives you've considered
I don't see other options for minimizing the cost of a mistake in the significant ranges.

Additional context
I started the conversation with an issue rather than a PR because the proposal is essential for our users, but still it's controversial. It doesn't have a happy path to solve the UX problem, so I prefer to discuss it with the community first. If we agree on the proposal, I'll implement it.

I've been thinking the optional prop can be named rangeStrategy and accept a union increase | decrease | both

  • increase means that we won't discard a range if the user picks a date "outside" the existing range
    for example, the user has 20/01/2024 - 20/02/2024 if they clicked 15/01/2024 means that we will change the startDate of the existing range and keep the endDate, the same works for endDate increasing. If we click inside the date range, the flow starts as usual from discarding the range.
  • decrease is the opposite of increase (thx, captain) we change a startDate and an endDate if a user clicks inside the range and discard if they clicked outside the range
  • both for cases when we will never discard the range but only adjust a startDate and an endDate according to the initial idea