react-date-range icon indicating copy to clipboard operation
react-date-range copied to clipboard

Any way to know if i select the start or the end of my range date?

Open JohnCoding94 opened this issue 8 years ago • 4 comments

Hi,

First, thanks for this great module :)

I would like to hide the component when a range date has been selected (keeping it open feels like a bug).

So in the onChange callback, i was expecting some information about the context (let's say something like context=startDate|endDate|actionButton), so if context is different from 'startDate' i keep it displayed, otherwise, i hide it.

Maybe there is already another way to implement that classic behavior?

JohnCoding94 avatar May 19 '18 20:05 JohnCoding94

Hi @JohnCoding94

Normally react-date-range controls focused range itself by the way you can control it them with focusedRange and onRangeFocusChange props. If you control it you can is it start date or end date like below.

<DateRangePicker
{...props}
focusedRange={this.state.focusedRange}
onRangeFocusChange={focusedRange=>{
const [rangeIndex, rangeStep] = focusedRange;
if(rangeStep === 0){
    console.log('start date');
} else {
    console.log('end date');
}

// also don't forget to set focused range
this.setState({focusedRange});
}}
/>

mkg0 avatar May 23 '18 08:05 mkg0

Feel free to ask anything if you stuck related to this topic 🙂

mkg0 avatar May 23 '18 08:05 mkg0

@mkg0 Thanks!

kesha-antonov avatar Aug 23 '18 17:08 kesha-antonov

screen shot 2018-08-23 at 20 24 06

Maybe it's error When I select first date - I get [0,1] When I select second date - I get [0,0]

kesha-antonov avatar Aug 23 '18 17:08 kesha-antonov