React-dates: Allow past dates for DateRangePicker

Created on 3 Jan 2017  路  8Comments  路  Source: airbnb/react-dates

Is it possible to select past dates in DateRangePicker?

Most helpful comment

I just struggled with this issue for a bit. I passed in as a prop

isOutsideRange={() => false}

This effectively lets any date be chosen.

All 8 comments

@mir3z
Why did you close the issue? Did you solve it? Mind tell others how?

See isOutsideRange in the documentation.

What documentation? The github readme doesn't mention anything about isOutsideRanger other than that it expects a function.

@winterblack that's a fair point. The "is" prefix means, by almost universal convention, that it's a predicate, which means it has to return a boolean (true or false). What it accepts might not be super apparent, but it takes a moment object representing a date, and leaves it to you to determine whether that date is outside the range or not.

PRs improving the documentation are always appreciated!

I just struggled with this issue for a bit. I passed in as a prop

isOutsideRange={() => false}

This effectively lets any date be chosen.

@ckeeney be aware that this solution is creating a new function each render call thus forcing a re-render of the component even though nothing may have changed.
If you want to avoid this just create the function as a constant outside your component like:
const falseFunc = ()=>false;
and then use the function as the prop
isOutsideRange={falseFunc}
This may add too little overhead to be noticeable ( unless you're rendering a ton of this in one view which seems unlikely ), but it's still a good pattern to follow.

Would be nice to understand the inputs to the function, like how do I say outside range if more than a year in the past.

Spec tests show a day being passed but how do I make it relative to the start/end without outside vars?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prztrz picture prztrz  路  3Comments

thomasdtucker picture thomasdtucker  路  3Comments

krissalvador27 picture krissalvador27  路  3Comments

AsasinCree picture AsasinCree  路  3Comments

sag1v picture sag1v  路  3Comments