I'm following this CodeSandBox example of how i can do a multiple material select.
This is my array that have all the possible options:
const permissionsGroupList = [
{ name: 'Sellers' },
{ name: 'Admins' }
];
This is my state that have my selected options:
const [groupPermissions, setGroupPermissions] = useState([]);
My function that add the selected option:
const handleChangeGroupPermissions = event => {
setGroupPermissions(event.target.value);
};
My template component:
<InputLabel id="mult-check-permissions">Grupo de permissões</InputLabel>
<Select
labelId="mult-check-permissions"
id="demo-mutiple-checkbox"
multiple
label="Grupo de permissões"
onChange={handleChangeGroupPermissions}
value={groupPermissions}
input={<Input disableUnderline={true} />}
renderValue={selected =>
selected.map(value => <Chip key={value.id} label={value.name} />)
}
>
{permissionsGroupList.map(permissionGroup => (
<MenuItem
key={permissionGroup.name}
value={{ name: permissionGroup.name }}
>
<Checkbox
checked={groupPermissions.some(
group => group.name === permissionGroup.name
)}
/>
<ListItemText primary={permissionGroup.name} />
</MenuItem>
))}
</Select>
In the example, when i select a already selected option, the element is removed from the array groupPermissions. In my case, when i click in an already selected option, this element is putting again inside the array.
There's something more that i have to do to get a similar result of the sandbox example?