Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
How to disable list of dates in MUI date picker

I want to disable MUI date picker future dates (only selected dates not all future dates)
I am getting array of dates from API which needs to be disabled from date picker.

Assume that below blackoutDates are what i am getting from API. So how to disable those dates ?

Below is my code

const getDisabledDates = () => {
 let blackoutDates = {[
    "2022-03-01",
    "2022-03-08"
    "2022-04-13",
    "2022-05-22"
 ]}
}
<DatePicker
  disablePast
  value={checkout.rideDate}
  shouldDisableDate={getDisabledDates}
  onChange={(newValue) => {
   dispatch(setRideDate(newValue?.toISOString().split('T')[0]))
   }}
  renderInput={(params) => <TextField  className={classes.datePickerStyle} {...params}/>}
/>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

shouldDisableDate is a function with the current date in param. So you need to compare this with your array, to enable / disable the date

const shouldDisableDate= date => {
  let blackoutDates = {[
    "2022-03-01",
    "2022-03-08"
    "2022-04-13",
    "2022-05-22"
  ]}

  return blackoutDates.includes(date);
}

This is an exemple, as your date is of type Date whereas your array contains strings. So you'll need to convert the date to a YYYY-MM-DD string first, using your prefered way :)

about 4 years ago · Juan Pablo Isaza Relatório

0

Handler prop shouldDisableDate passes a date argument to the function you provide. So, your function could look like:

const getDisabledDates = (date) => {
 let blackoutDates = [
    "2022-03-01",
    "2022-03-08"
    "2022-04-13",
    "2022-05-22"
 ];
 // check `date` object against blackoutDates.
 // return true | false 
}

Keep in mind that the date parameter is a vanilla Date object. More info at MUI documentation. In the example, you can see how a function isWeekend is passed to a prop shouldDisableDate. According to date-fns documentation this function accepts the date object. I suggest You play around in the demo that MUI provides.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda