Skip to content

Commit

Permalink
Merge pull request #5915 from gucal/master
Browse files Browse the repository at this point in the history
Fix #5914 - MultiSelect: Enter | Space Overlay Closes
  • Loading branch information
gucal authored Feb 7, 2024
2 parents 46742d5 + 2cd67b8 commit 5c8d402
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 5c8d402

Please sign in to comment.