Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5914 - MultiSelect: Enter | Space Overlay Closes #5915

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading