From 122d347492e7275c127cb5a5d6c0437d37af7aa5 Mon Sep 17 00:00:00 2001 From: weaseldotro <1822852+weaseldotro@users.noreply.github.com> Date: Fri, 16 Oct 2020 11:48:33 +0300 Subject: [PATCH] DropDown: add select event, fix closing when click outside of body --- src/Dropdown/Dropdown.svelte | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Dropdown/Dropdown.svelte b/src/Dropdown/Dropdown.svelte index 52cb6acc..80ba0a47 100644 --- a/src/Dropdown/Dropdown.svelte +++ b/src/Dropdown/Dropdown.svelte @@ -113,6 +113,7 @@ * @typedef {{ id: DropdownItemId; text: DropdownItemText; }} DropdownItem */ + import { createEventDispatcher } from "svelte"; import WarningFilled16 from "carbon-icons-svelte/lib/WarningFilled16"; import { ListBox, @@ -121,6 +122,8 @@ ListBoxMenuItem, } from "../ListBox"; + const dispatch = createEventDispatcher(); + let selectedId = undefined; let highlightedIndex = -1; @@ -136,6 +139,9 @@ highlightedIndex = index; } + $: if (selectedIndex > -1) { + dispatch("select", { selectedId, selectedIndex, selectedItem }); + } $: inline = type === "inline"; $: selectedItem = items[selectedIndex]; $: if (!open) { @@ -143,7 +149,7 @@ } -