Reputation: 916
I'm using Material UI (5)
and the Autocomplete
component with multiselect
option enabled. I'm also using the "checkbox" customization found in MUI documentation. I'm trying to do a small improvement to be able to "Check/Uncheck All" options. To do that, I'm using PopperComponent
property.
Follow the Code Sandbox example : https://codesandbox.io/s/checkboxestags-material-demo-forked-5b0pt
However, I've got 2 problems that I don't know how to solve:
ClickAwayListener
intercepts a click outside the component, but it's not true;Upvotes: 1
Views: 3740
Reputation: 1791
Because you're using ClickAwayListener
, So it considered that 'Select all' Checkbox
is out of it.
You can prevent that by adding onMouseDown
event:
<Checkbox
checked={checkAll}
onChange={checkAllChange}
id="check-all"
sx={{ marginRight: "8px" }}
onMouseDown={(e) => e.preventDefault()} // <== add this
/>
Upvotes: 3