From 2cd67b8351fe70a1dc0c14a5dcba1ec080f5ecf3 Mon Sep 17 00:00:00 2001 From: gucal Date: Wed, 7 Feb 2024 14:53:51 +0300 Subject: [PATCH] Fix #5914 - MultiSelect: Enter | Space Overlay Closes --- components/lib/multiselect/MultiSelect.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/components/lib/multiselect/MultiSelect.js b/components/lib/multiselect/MultiSelect.js index 02a430f1cb..5582c33456 100644 --- a/components/lib/multiselect/MultiSelect.js +++ b/components/lib/multiselect/MultiSelect.js @@ -208,8 +208,6 @@ export const MultiSelect = React.memo( if (event.shiftKey) onOptionSelectRange(event, focusedOptionIndex); else onOptionSelect(event, visibleOptions[focusedOptionIndex]); } - - hide(); } event.preventDefault(); @@ -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); @@ -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 = () => {