mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 11:36:36 +00:00
Added clear function
This commit is contained in:
parent
abfc472c82
commit
ae1d34bd3e
1 changed files with 11 additions and 7 deletions
|
@ -123,6 +123,14 @@
|
||||||
highlightedIndex = index;
|
highlightedIndex = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clear() {
|
||||||
|
selectedIndex = -1;
|
||||||
|
highlightedIndex = -1;
|
||||||
|
open = false;
|
||||||
|
inputValue = "";
|
||||||
|
ref?.focus();
|
||||||
|
}
|
||||||
|
|
||||||
afterUpdate(() => {
|
afterUpdate(() => {
|
||||||
if (open) {
|
if (open) {
|
||||||
ref.focus();
|
ref.focus();
|
||||||
|
@ -140,6 +148,8 @@
|
||||||
$: if (selectedIndex > -1) {
|
$: if (selectedIndex > -1) {
|
||||||
selectedId = items[selectedIndex].id;
|
selectedId = items[selectedIndex].id;
|
||||||
dispatch("select", { selectedId, selectedIndex, selectedItem });
|
dispatch("select", { selectedId, selectedIndex, selectedItem });
|
||||||
|
} else {
|
||||||
|
clear();
|
||||||
}
|
}
|
||||||
$: ariaLabel = $$props["aria-label"] || "Choose an item";
|
$: ariaLabel = $$props["aria-label"] || "Choose an item";
|
||||||
$: menuId = `menu-${id}`;
|
$: menuId = `menu-${id}`;
|
||||||
|
@ -286,13 +296,7 @@
|
||||||
{#if inputValue}
|
{#if inputValue}
|
||||||
<ListBoxSelection
|
<ListBoxSelection
|
||||||
on:clear
|
on:clear
|
||||||
on:clear="{() => {
|
on:clear="{clear}"
|
||||||
selectedIndex = -1;
|
|
||||||
highlightedIndex = -1;
|
|
||||||
open = false;
|
|
||||||
inputValue = '';
|
|
||||||
ref.focus();
|
|
||||||
}}"
|
|
||||||
translateWithId="{translateWithId}"
|
translateWithId="{translateWithId}"
|
||||||
disabled="{disabled}"
|
disabled="{disabled}"
|
||||||
open="{open}"
|
open="{open}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue