Created
August 31, 2020 04:47
-
-
Save Kannndev/597db43a7b456a918e0bcc320d8d91fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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