edwardfxiao / react-minimal-datetime-range

A react component for date time range picker. Online demo examples
https://edwardfxiao.github.io/react-minimal-datetime-range/
MIT License
16 stars 7 forks source link

How can I disable all the dates before current date. #9

Closed HarkiratShopism1 closed 4 months ago

HarkiratShopism1 commented 8 months ago

I am using "duration" to pick from a certain date to a certain date and I want to disable all the previous dates so that the user can not select them as the first date. How can I do this.

edwardfxiao commented 8 months ago

Let's say user select Jan 01 2024, and the duration is 2, the end date is automatically set Jan 03 2024, and you want to disable all the dates before Jan 01 2024? And user can only select Jan 02 2024 and after and so on? Meaning that user cannot select back again?

HarkiratShopism1 commented 8 months ago

Yes exactly. How can I achieve this?

edwardfxiao commented 8 months ago

I don't think it's possible for now

edwardfxiao commented 8 months ago

@HarkiratShopism1 Hi, in verison2.1.0 I provide a onChooseDate property for this. Each time you clicked a date, you set supportDateRange with it.

Something like this:

const [mySupportDateRange, setMySupportDateRange] = useState(['2024-01-10', ''])
...
<RangePicker
  ...
  supportDateRange={mySupportDateRange}
  duration={2}
  onChooseDate={res => {
    setMySupportDateRange(prev => {
      prev[0] = res.value;
      return prev;
    });
  }}
/>

Try if it works.