React-dates: How to handle only selecting 1 date on the DateRangePicker

Created on 10 Feb 2017  路  5Comments  路  Source: airbnb/react-dates

We notice something rather strange, we can't select a single date in the DateRangePicker. Should this be something we could handle or is this a bug?

Even the React Storyboard demo doesn't allow you to select a single date.

Most helpful comment

To be specific, just set minimumNights={0} in order to achieve the effect of the issue in question.

All 5 comments

What do you mean? The DateRangePicker is designed to select a range, ie two dates. The SingleDatePicker allows you to select just one date, if that's what you need. Both seem functional in the demo. Can you post a gif or a screenshot of what you're seeing?

@majapw, For example, this can be actual for Reports, in most cases we select a date range, but sometimes we need data for one day only, for today or for yesterday.
Like this:
selection

Partially we solved this with code:

onDatesChange({startDate, endDate}) {
   if (this.state.startDate.diff(startDate, 'days') == 0 
       && this.state.endDate.diff(endDate, 'days') == 0) {
        if (this.state.focusedInput == "startDate")
            endDate = startDate;
        else
            startDate = endDate;
    }     
    this.setState({startDate, endDate});
}

@majapw: Thanks for the quick comment, I was going to explain what we are trying to do, however, I think @RodionNikolaev just answered.

@RodionNikolaev: I will try this out, many thanks.

I am closing this, as of 7.0.0, this feature is now available.
@majapw: thanks for including this feature.

To be specific, just set minimumNights={0} in order to achieve the effect of the issue in question.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prztrz picture prztrz  路  3Comments

aaronvanston picture aaronvanston  路  3Comments

HartiganHM picture HartiganHM  路  3Comments

arthurvi picture arthurvi  路  3Comments

mrseanbaines picture mrseanbaines  路  3Comments