The code below explains the problem. This is not a priority bug since there is a workaround (last code block):
// Options state using React `useState` hook
const [indicesOptions, setIndicesOptions] = useState<Option[]>([
{label: 'foo', checked: 'on'},
{label: 'foo', checked: 'on'},
]);
// Rendered selectable list
<EuiSelectable
allowExclusions={false}
options={indicesOptions}
onChange={options => {
const newSelectedIndices: string[] = [];
options.forEach(({ label, checked }) => {
if (checked === 'on') {
newSelectedIndices.push(label);
}
});
setIndicesOptions(options);
}}
searchable
height={300}
>
{(list, search) => (
<EuiPanel paddingSize="s" hasShadow={false}>
{search}
{list}
</EuiPanel>
)}
</EuiSelectable>
// DOESN'T WORK
// Deselecting all options programmatically via building new `indicesOptions` (new objects)
<EuiLink
onClick={() => {
setIndicesOptions(indicesOptions.map(option => ({
...option,
checked: undefined,
})));
}}
>
De-select all
</EuiLink>
// WORKS!
// Deselecting all options programmatically via modifying each `indicesOption` object
<EuiLink
onClick={() => {
indicesOptions.forEach(option => {
option.checked = undefined;
});
}}
>
De-select all
</EuiLink>
The code below explains the problem. This is not a priority bug since there is a workaround (last code block):