karsten-design-system 1.1.84 → 1.1.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +31 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -711,11 +711,41 @@ function MultiSelect(props) {
|
|
|
711
711
|
const [highlightedIndex, setHighlightedIndex] = useState(-1);
|
|
712
712
|
const containerRef = useRef(null);
|
|
713
713
|
const inputRef = useRef(null);
|
|
714
|
+
const hasOnInputChange = props?.onInputChange !== undefined;
|
|
714
715
|
const normalize = (str) => str
|
|
715
716
|
.normalize('NFD')
|
|
716
717
|
.replace(/[\u0300-\u036f]/g, '')
|
|
717
718
|
.toLowerCase();
|
|
718
|
-
const
|
|
719
|
+
const ensureValuesInOptions = (optionsList, currentValues) => {
|
|
720
|
+
if (!currentValues || currentValues.length === 0)
|
|
721
|
+
return optionsList;
|
|
722
|
+
const allOptions = [...optionsList];
|
|
723
|
+
currentValues.forEach((selected) => {
|
|
724
|
+
const exists = allOptions.some((opt) => opt.value === selected.value);
|
|
725
|
+
if (!exists) {
|
|
726
|
+
allOptions.unshift(selected);
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
return allOptions;
|
|
730
|
+
};
|
|
731
|
+
const filteredOptions = (() => {
|
|
732
|
+
const allOptions = ensureValuesInOptions(options, props.value);
|
|
733
|
+
// if (!isReadOnly) {
|
|
734
|
+
// return allOptions.filter((option) =>
|
|
735
|
+
// normalize(option.label).includes(normalize(searchText))
|
|
736
|
+
// )
|
|
737
|
+
// }
|
|
738
|
+
if (!isReadOnly) {
|
|
739
|
+
const filtered = allOptions.filter((option) => normalize(option.label).includes(normalize(searchText)));
|
|
740
|
+
const selected = Array.isArray(props.value) ? props.value : [];
|
|
741
|
+
const selectedNotInFiltered = selected.filter((sel) => !filtered.find((opt) => opt.value === sel.value));
|
|
742
|
+
return [...selectedNotInFiltered, ...filtered];
|
|
743
|
+
}
|
|
744
|
+
if (hasOnInputChange) {
|
|
745
|
+
return allOptions;
|
|
746
|
+
}
|
|
747
|
+
return allOptions;
|
|
748
|
+
})();
|
|
719
749
|
const toggleDropdown = () => {
|
|
720
750
|
if (!disabled && !isLoading) {
|
|
721
751
|
const newState = !isOpen;
|