mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-20 12:23:02 +00:00
fix(multi-select): correctly select correct item in filterable multiselect
Fixes #922
This commit is contained in:
parent
96930a4065
commit
f6c9c8cea1
1 changed files with 15 additions and 3 deletions
|
@ -392,9 +392,21 @@
|
||||||
on:keydown|stopPropagation="{({ key }) => {
|
on:keydown|stopPropagation="{({ key }) => {
|
||||||
if (key === 'Enter') {
|
if (key === 'Enter') {
|
||||||
if (highlightedIndex > -1) {
|
if (highlightedIndex > -1) {
|
||||||
sortedItems[highlightedIndex].checked = !sortedItems[
|
if (filterable) {
|
||||||
highlightedIndex
|
const filteredItemId = filteredItems[highlightedIndex].id;
|
||||||
].checked;
|
const filteredItemIndex = sortedItems
|
||||||
|
.map((item) => item.id)
|
||||||
|
.indexOf(filteredItemId);
|
||||||
|
|
||||||
|
sortedItems = sortedItems.map((item, i) => {
|
||||||
|
if (i !== filteredItemIndex) return item;
|
||||||
|
return { ...item, checked: !item.checked };
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
sortedItems[highlightedIndex].checked = !sortedItems[
|
||||||
|
highlightedIndex
|
||||||
|
].checked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (key === 'Tab') {
|
} else if (key === 'Tab') {
|
||||||
open = false;
|
open = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue