karsten-design-system 1.1.84 → 1.1.85

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 CHANGED
@@ -711,11 +711,33 @@ 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 filteredOptions = options.filter((option) => normalize(option.label).includes(normalize(searchText)));
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) => normalize(option.label).includes(normalize(searchText)));
735
+ }
736
+ if (hasOnInputChange) {
737
+ return allOptions;
738
+ }
739
+ return allOptions;
740
+ })();
719
741
  const toggleDropdown = () => {
720
742
  if (!disabled && !isLoading) {
721
743
  const newState = !isOpen;