Skip to content

Commit

Permalink
Fix #5914 - MultiSelect: Enter | Space Overlay Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
gucal committed Feb 7, 2024
1 parent 46742d5 commit 2cd67b8
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions components/lib/multiselect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ export const MultiSelect = React.memo(
if (event.shiftKey) onOptionSelectRange(event, focusedOptionIndex);
else onOptionSelect(event, visibleOptions[focusedOptionIndex]);
}

hide();
}

event.preventDefault();
Expand Down Expand Up @@ -535,6 +533,10 @@ export const MultiSelect = React.memo(
return list.findIndex((item) => value.some((val) => ObjectUtils.equals(val, getOptionValue(item), equalityKey)));
};

const isEquals = (value1, value2) => {
return ObjectUtils.equals(value1, value2, equalityKey);
};

const isSelected = (option) => {
if (props.value) {
const optionValue = getOptionValue(option);
Expand Down Expand Up @@ -687,7 +689,16 @@ export const MultiSelect = React.memo(
};

const findSelectedOptionIndex = () => {
return hasSelectedOption ? visibleOptions?.findIndex((option) => isValidSelectedOption(option)) : -1;
if (hasSelectedOption()) {
for (let index = props.value.length - 1; index >= 0; index--) {
const value = props.value[index];
const matchedOptionIndex = visibleOptions.findIndex((option) => isValidSelectedOption(option) && isEquals(value, getOptionValue(option)));

if (matchedOptionIndex > -1) return matchedOptionIndex;
}
}

return -1;
};

const findFirstFocusedOptionIndex = () => {
Expand Down

0 comments on commit 2cd67b8

Please sign in to comment.