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

197
Visualizações
Matrial-UI <Autocomplete /> search by multiple parameters

So i've started learning Material UI and i have a question.

We have an object

const top100Films = [
  { label: 'The Shawshank Redemption', year: 1994 },
  { label: 'The Godfather', year: 1972 }, 

  * ...More items *
]

Right now if i set getOptionLabel = {option => option.label} in my Autocomplete it will only search by matching label(title) so if i enter a year i.e "1994" it won't show "The Shawshank Redemption" in my search results, and if i set it to option.year it will only search by year and any input but year will be invalid.

Here's my question: Is there a way to set it so i can search both by title or by year.

Solution:

<Autocomplete
  ...
  filterOptions={(options, { inputValue }) => options.filter(item => item.label.toLowerCase().includes(inputValue) || item.year.toString().includes(inputValue) )}
/>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

MUI Autocomplete API has filterOptions (docs here) prop where you can set custom filtering.

I would implement it something like:

<Autocomplete
  ...
  filterOptions={(options, { inputValue }) => options.filter(item => item.label.includes(inputValue) || item.year.toString.includes(inputValue) )}
/>
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