mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
fix(combo-box): apply filter when open
This commit is contained in:
parent
fb9e1d5ac7
commit
f19589ac54
1 changed files with 5 additions and 2 deletions
|
@ -30,6 +30,7 @@
|
|||
ListBoxSelection
|
||||
} from '../ListBox';
|
||||
|
||||
let selectedId = undefined;
|
||||
let inputRef = undefined;
|
||||
let inputValue = undefined;
|
||||
let highlightedIndex = -1;
|
||||
|
@ -49,6 +50,7 @@
|
|||
afterUpdate(() => {
|
||||
if (open) {
|
||||
inputRef.focus();
|
||||
filteredItems = items.filter(item => shouldFilterItem(item, value));
|
||||
} else {
|
||||
highlightedIndex = -1;
|
||||
inputValue = selectedItem ? selectedItem.text : '';
|
||||
|
@ -165,10 +167,11 @@
|
|||
<ListBoxMenu aria-label={ariaLabel} {id}>
|
||||
{#each filteredItems as item, i (item.id || i)}
|
||||
<ListBoxMenuItem
|
||||
active={selectedIndex === i}
|
||||
active={selectedIndex === i || selectedId === item.id}
|
||||
highlighted={highlightedIndex === i || selectedIndex === i}
|
||||
on:click={() => {
|
||||
selectedIndex = i;
|
||||
selectedId = item.id;
|
||||
selectedIndex = items.map(({ id }) => id).indexOf(filteredItems[i].id);
|
||||
open = false;
|
||||
}}
|
||||
on:mouseenter={() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue