hypeserver / react-date-range

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

Detect endDate selection. #400

Open GustavoSD opened 3 years ago

GustavoSD commented 3 years ago

Subject of the issue

There's a way I can trigger a function when selecting the end date?

djparulan commented 3 years ago

Have you found an answer for this?

GustavoSD commented 3 years ago

Have you found an answer for this? Nope, not a solution for this. I had to change to another library.

izzappel commented 3 years ago

You can figure out which date (start or end date) is "focused" by using the focusedRange. In the onChange handler you can then use this information to check which date was set.

Maybe this helps: https://codesandbox.io/s/red-morning-jrdd2?file=/src/Picker.js

FedyaNyet commented 3 years ago

This doesn't work when selecting a predefined range... any additional suggestions for that scenario?

dhikatb commented 3 years ago

add hasCustomRendering as true in your staticRanges then add some trigger event in renderStaticRangeLabel

<DateRangePicker
  .....
  renderStaticRangeLabel={(range) => (
      <div
          onClick={() => {
               // add your custom function here
          }}
      >
          {range.label}
      </div>
  )}
  staticRanges={[
    label: 'Last 30 days',
    hasCustomRendering: true,
    range: () => ({
        startDate: ...,
        endDate: ...,
    })
  ]}
/>