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

111
Views
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 answers
Answer question

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 Report

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 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!