Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
Checking checkbox inside Autocompletion with MUI
[
  { label: 'First', checked: false }, 
  { label: 'Second', checked: true }
]

Here is a very short snippet of how the data could look like. I am using Material UI's Autocomplete, to make it possible for searching on labels. These labels are having a checkbox.

Problem is, I can't use onChange on <Checkbox /> when its a renderOption The Autocomplete just closes, without doing any action

<Autocomplete
  disableCloseOnSelect={true}
  options={array}
  getOptionLabel={option => option.label.toString()}
  renderInput={params => (
    <TextField
      {...params}
      fullWidth
      label="Select label"
      variant="outlined"
      error={false}
    />
  )}
  renderOption={opt => (
    <div>
      <Checkbox
        checked={opt.checked}
        onChange={() => alert('not being fired...')}
      />
      <p>{opt.label}</p>
    </div>
  )}
/>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You shouldn't use onChange in Checkbox, You should use onChange prop of Autocomplete, and set default value by value prop
and Checkbox receive its props from renderOption's props

const [selectedOptions, setSelectedOptions] = useState([]);

useEffect(() => {
   setSelectedOptions(options.filter(op => op.checked));
}, []);

<Autocomplete
   options={options}
   value={selectedOptions}
   onChange={(event, newValue) => {
      setSelectedUsers(newValue);
   }
   renderOption={(props, option, { selected }) => (
       <div {...props}>
          <Checkbox checked={selected} />
          <p>{option.name}</p>
        </div>
   )}
   disableCloseOnSelect
/>
about 4 years ago · Juan Pablo Isaza Denunciar

0

onChange event will work in Checkbox provided in renderOption function but it only works when you click on checkbox not anywhere else on list item. You can use onClick on the parent div if that fulfills your purpose.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda