Skip to content
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

[DataPicker] Allow for passing undefined startDate, endDate props when enableRangeSelect is set to true #2333

Closed
Juliakas opened this issue Nov 8, 2024 · 3 comments · Fixed by #2334
Assignees
Labels
enhancement New feature or request

Comments

@Juliakas
Copy link
Contributor

Juliakas commented Nov 8, 2024

Feature

Allow for passing undefined startDate, endDate props to DatePicker component when enableRangeSelect is set to true. This allows for not having any initial date range set.

That being said, if there is no initial range set then it would be nice to force calendar to navigate to somewhere else than "today", DatePicker could have initialFocusedDay prop or something like that.

Examples

interface DateRange {
  startDate: Date;
  endDate: Date;
}

const MyComponent = ({ limits }: { limits: DateRange }) => {

  const [dateRange, setDateRange] = useState<DateRange>();

  return <DatePicker 
    enableRangeSelect
    startDate={dateRange?.startDate}
    endDate={dateRange?.endDate}
    initialFocusedDay={limits.startDate}
    onChange={(startDate, endDate) => setDateRange({ startDate, endDate })}
    ....
  />
}
@Juliakas Juliakas added the enhancement New feature or request label Nov 8, 2024
@r100-stack r100-stack self-assigned this Nov 8, 2024
@mayank99
Copy link
Contributor

mayank99 commented Nov 8, 2024

I think we can support undefined in startDate and endDate, since it almost feels like a bug if undefined doesn't work.

However, I just want to note that date range selection is not recommended. For better UX, we instead recommend using two separate date fields for "Start date" and "End date". In the future, the enableRangeSelect prop might be deprecated.

@r100-stack
Copy link
Member

I think we can support undefined in startDate and endDate, since it almost feels like a bug if undefined doesn't work.

Support for setting startDate and endDate as undefined has now been added to 3.16.0 🚀

To keep the behavior simple, both of those props have to either be Date or undefined. Passing Date to just one of them is not allowed. If this ever happens, a dev-only console warning is shown:

Image


But as @mayank99 mentioned, instead of the range DatePicker, we actually recommend two separate DatePickers for better UX. (More info with examples)

@Juliakas
Copy link
Contributor Author

Juliakas commented Nov 20, 2024

I think we can support undefined in startDate and endDate, since it almost feels like a bug if undefined doesn't work.

However, I just want to note that date range selection is not recommended. For better UX, we instead recommend using two separate date fields for "Start date" and "End date". In the future, the enableRangeSelect prop might be deprecated.

It looked like a good pattern tbh, another example could be how booking.com allows date range selecting which I find convenient and less clicks:
Image

Also in linked example implementation is a bit more bulky, we have something like this going on right now: Image

Other than that thanks for implemting this undefined start/endDate feature

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

Successfully merging a pull request may close this issue.

3 participants