Skip to content

Commit 5dd3a44

Browse files
author
Richard P. Field III
committed
feat: Update the combobox example
1 parent d22d03e commit 5dd3a44

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/routes/+page.svelte

+28-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import type { SelectOption } from '$lib/combobox/types';
55
import type { ComboboxSearchEvent } from '$lib/combobox/types';
66
import type { ComboboxChangeEvent } from '$lib/combobox/types';
7+
import type { ChipListChangeEvent } from '$lib/chiplist/types';
78
89
import { COLOR_MODE, FILL_MODE } from '$lib/types';
910
@@ -16,6 +17,7 @@
1617
import Menu from '$lib/menu/Menu.svelte';
1718
import Paginator from '$lib/paginator/Paginator.svelte';
1819
import Combobox from '$lib/combobox/Combobox.svelte';
20+
import ChipList from '$lib/chiplist/ChipList.svelte';
1921
2022
export let data: PageData;
2123
@@ -84,13 +86,25 @@
8486
}
8587
];
8688
89+
let comboboxValue: SelectOption | undefined = undefined;
90+
8791
let filteredComboboxOptions = comboboxOptions;
8892
93+
let selectedComboboxOptions: SelectOption[] = [];
94+
8995
function filterComboboxOptions(searchText: string) {
90-
const filteredOptions = comboboxOptions.filter((x) => {
91-
return x.text.toLocaleLowerCase().includes(searchText);
96+
const selectedValues = selectedComboboxOptions.map((x) => {
97+
return x.value;
9298
});
9399
100+
const filteredOptions = comboboxOptions
101+
.filter((x) => {
102+
return !selectedValues.includes(x.value);
103+
})
104+
.filter((x) => {
105+
return x.text.toLocaleLowerCase().includes(searchText);
106+
});
107+
94108
return filteredOptions;
95109
}
96110
@@ -101,9 +115,15 @@
101115
}
102116
103117
function handleComboboxChange(e: ComboboxChangeEvent) {
104-
const searchText = '';
118+
selectedComboboxOptions = [...selectedComboboxOptions, e.detail.value];
105119
106-
filteredComboboxOptions = filterComboboxOptions(searchText);
120+
filteredComboboxOptions = filterComboboxOptions('');
121+
122+
comboboxValue = undefined;
123+
}
124+
125+
function handleChipListChange(e: ChipListChangeEvent) {
126+
selectedComboboxOptions = [...e.detail.value];
107127
}
108128
</script>
109129

@@ -187,12 +207,15 @@
187207
<section>
188208
<h1 class="mb-4 text-2xl">Combobox</h1>
189209

190-
<div class="w-1/4">
210+
<div class="flex w-1/4 flex-col gap-2">
191211
<Combobox
212+
bind:value={comboboxValue}
192213
options={filteredComboboxOptions}
193214
on:search={handleComboboxSearch}
194215
on:change={handleComboboxChange}
195216
/>
217+
218+
<ChipList value={selectedComboboxOptions} on:change={handleChipListChange} />
196219
</div>
197220
</section>
198221

0 commit comments

Comments
 (0)