mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 19:46:36 +00:00
changed ComboBox to not erase the user typed value
This commit is contained in:
parent
8b57f235f2
commit
73aac81c92
1 changed files with 23 additions and 10 deletions
|
@ -174,7 +174,7 @@
|
|||
filteredItems = [];
|
||||
if (!selectedItem) {
|
||||
selectedId = undefined;
|
||||
value = "";
|
||||
// value = "";
|
||||
highlightedIndex = -1;
|
||||
highlightedId = undefined;
|
||||
} else {
|
||||
|
@ -207,6 +207,18 @@
|
|||
$: comboId = `combo-${id}`;
|
||||
$: highlightedId = items[highlightedIndex] ? items[highlightedIndex].id : 0;
|
||||
$: filteredItems = items.filter((item) => shouldFilterItem(item, value));
|
||||
|
||||
$: if (items.filter((item) => item.text === value).length > 0) {
|
||||
items.map((item) => {
|
||||
if (item.text === value) {
|
||||
selectedItem = item;
|
||||
selectedId = item.id;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
selectedItem = undefined;
|
||||
selectedId = undefined;
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window
|
||||
|
@ -275,14 +287,14 @@
|
|||
class:bx--text-input--light="{light}"
|
||||
class:bx--text-input--empty="{value === ''}"
|
||||
on:input="{({ target }) => {
|
||||
if (!open && target.value.length > 0) {
|
||||
open = true;
|
||||
}
|
||||
|
||||
if (!value.length) {
|
||||
clear();
|
||||
open = true;
|
||||
}
|
||||
// if (!open && target.value.length > 0) {
|
||||
// open = true;
|
||||
// }
|
||||
value = target.value;
|
||||
// if (!value.length) {
|
||||
// clear();
|
||||
// open = true;
|
||||
// }
|
||||
}}"
|
||||
on:keydown
|
||||
on:keydown|stopPropagation="{(e) => {
|
||||
|
@ -352,7 +364,7 @@
|
|||
class="bx--list-box__invalid-icon bx--list-box__invalid-icon--warning"
|
||||
/>
|
||||
{/if}
|
||||
{#if value}
|
||||
{#if false}
|
||||
<ListBoxSelection
|
||||
on:clear
|
||||
on:clear="{clear}"
|
||||
|
@ -390,6 +402,7 @@
|
|||
return;
|
||||
}
|
||||
selectedId = item.id;
|
||||
value = item.text;
|
||||
open = false;
|
||||
|
||||
if (filteredItems[i]) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue