hypeserver / react-date-range

A React component for choosing dates and date ranges.
MIT License
2.57k stars 658 forks source link

staticRange with only one startDate or endDate not triggering isSelected handler #548

Open tnormington opened 2 years ago

tnormington commented 2 years ago

Subject of the issue

I'm trying to create a staticRange of "More than 2 years ago". Setting startDate to null and endDate to the correct date object for the staticRange entry. The isSelected handler is not triggering when clicked.

[BUG] Bug Reproduce Steps

  1. Setup a DateRange component with this staticRange (uses date-fns set()):
    [{
    label: 'More than 2 years ago',
    range: () => ({
      startDate: null,
      endDate: set(new Date(), { year: new Date().getFullYear() - 2 })
    }),
    isSelected(range) {
      debugger;
    }
    }]
  2. Select this staticRange on the front-end
  3. Debugger is not triggered

[BUG] Expected behaviour

I am expecting the isSelected method to run

Environment

Package Version: 1.4.0 React version: 16.14 Node version: 8.6 Browser: Chrome

karakum commented 2 years ago

I faced with same issue, but with both startDate & endDate as null (case "All time" not highlighted)