Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const selectAllValues = (checked) => {
const optionsWithFilterApplied = filteredOptions();
const newOptions = [...value];
optionsWithFilterApplied.filter(({disabled}) => !disabled).forEach((o) => {
const index = newOptions.findIndex(elem => elem.value === o.value);
if (checked) {
if (index === -1) {
newOptions.push(o)
}
} else {
if (index !== -1) {
newOptions.splice(index, 1);
}
}
});
return newOptions;
};
const filteredOptions = () => {
const filtered = customFilterOptions
? customFilterOptions(options, searchText)
: filterOptions(options, searchText);
return filtered;
}
const isAllOptionSelected =
filteredOptions()
.filter(({ disabled }) => !disabled)
.every((elem) =>
value.find((selected) => selected.value === elem.value) ? true : false
) && value.length;
const isPartialSelected = filteredOptions().some((elem) =>
value.find((selected) => selected.value === elem.value) ? true : false
) && !isAllOptionSelected;
{hasSelectAll && filteredOptions().filter(({disabled}) => !disabled).length > 0 && (
<SelectItem
focused={focusIndex === 1}
tabIndex={1}
checked={isAllOptionSelected}
option={selectAllOption}
onSelectionChanged={selectAllChanged}
onClick={() => handleItemClicked(0)}
itemRenderer={ItemRenderer}
disabled={disabled}
isPartialSelected={isPartialSelected}
/>
)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment