Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
React Js - Material UI - Change Min Date as per previous selection

I have 2 date pickers in material UI-

From Date -

<KeyboardDatePicker
 value={initialDateFrom}
 disableFuture={true}
onChange={handleFromDateChange}
>
</KeyboardDatePicker>

To Date -

<KeyboardDatePicker
 value={initialDateTo}
 disableFuture={true}
onChange={handleToDateChange}
>
</KeyboardDatePicker>

const [initialDateFrom , setInitialDateFrom]= useState<any>(null);
const [initialDateTo , setInitialDateTo]= useState<any>(null);

const handleFromDateChange =(event:any , value :any)=>{
  setInitialDateFrom(value)
}

const handleToDateChange =(event:any , value :any)=>{
  setInitialDateTo(value)
}

What I am trying to achieve -

If I select 11-Oct-2021 as From date , I want to disable all the previous dates in To Date date picker to 11-Oct-2021. To Date - Date picker should show only future dates from 11-Oct-2021.

What I tried -

minDate = {initialDateFrom} in To Date datepicker

value.minDate = initialDateFrom in handleFromDateChange

But this did not helped.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can try this approach, I have created one more state to handle minDate

const [initialDateFrom , setInitialDateFrom]= useState<any>(null);
const [minDate, setMinDate] = useState<any>(null);
const [initialDateTo , setInitialDateTo]= useState<any>(new Date());

const handleFromDateChange =(event:any , value :any)=>{
  setInitialDateFrom(new Date(value));
  setMinDate(new Date(value))
}

const handleToDateChange =(event:any , value :any)=>{
  setInitialDateTo(value)
}

<KeyboardDatePicker
 value={initialDateFrom}
 disableFuture={true}
 onChange={handleFromDateChange}
>
</KeyboardDatePicker>

<KeyboardDatePicker
 value={initialDateTo}
 minDate={minDate}
 onChange={handleToDateChange}
>
</KeyboardDatePicker>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!