mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +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
|
ListBoxSelection
|
||||||
} from '../ListBox';
|
} from '../ListBox';
|
||||||
|
|
||||||
|
let selectedId = undefined;
|
||||||
let inputRef = undefined;
|
let inputRef = undefined;
|
||||||
let inputValue = undefined;
|
let inputValue = undefined;
|
||||||
let highlightedIndex = -1;
|
let highlightedIndex = -1;
|
||||||
|
@ -49,6 +50,7 @@
|
||||||
afterUpdate(() => {
|
afterUpdate(() => {
|
||||||
if (open) {
|
if (open) {
|
||||||
inputRef.focus();
|
inputRef.focus();
|
||||||
|
filteredItems = items.filter(item => shouldFilterItem(item, value));
|
||||||
} else {
|
} else {
|
||||||
highlightedIndex = -1;
|
highlightedIndex = -1;
|
||||||
inputValue = selectedItem ? selectedItem.text : '';
|
inputValue = selectedItem ? selectedItem.text : '';
|
||||||
|
@ -165,10 +167,11 @@
|
||||||
<ListBoxMenu aria-label={ariaLabel} {id}>
|
<ListBoxMenu aria-label={ariaLabel} {id}>
|
||||||
{#each filteredItems as item, i (item.id || i)}
|
{#each filteredItems as item, i (item.id || i)}
|
||||||
<ListBoxMenuItem
|
<ListBoxMenuItem
|
||||||
active={selectedIndex === i}
|
active={selectedIndex === i || selectedId === item.id}
|
||||||
highlighted={highlightedIndex === i || selectedIndex === i}
|
highlighted={highlightedIndex === i || selectedIndex === i}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
selectedIndex = i;
|
selectedId = item.id;
|
||||||
|
selectedIndex = items.map(({ id }) => id).indexOf(filteredItems[i].id);
|
||||||
open = false;
|
open = false;
|
||||||
}}
|
}}
|
||||||
on:mouseenter={() => {
|
on:mouseenter={() => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue