From 334ea7f063bfbf06e8f45207d71fc11e94a5832f Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Thu, 30 Jul 2020 16:42:36 -0700 Subject: [PATCH] chore(ui-shell): apply toggle behavior to HeaderAction Dispatch open/close events --- src/UIShell/GlobalHeader/HeaderAction.svelte | 24 ++++++++++++----- src/UIShell/UIShell.Story.svelte | 27 +++++++++++++------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/UIShell/GlobalHeader/HeaderAction.svelte b/src/UIShell/GlobalHeader/HeaderAction.svelte index 6d6f5d1e..6480f2d1 100644 --- a/src/UIShell/GlobalHeader/HeaderAction.svelte +++ b/src/UIShell/GlobalHeader/HeaderAction.svelte @@ -18,9 +18,18 @@ */ export let text = undefined; + /** + * Obtain a reference to the button HTML element + * @type {null | HTMLButtonElement} [ref=null] + */ + export let ref = null; + import { Icon } from "../../Icon"; + import { createEventDispatcher } from "svelte"; import { slide } from "svelte/transition"; + const dispatch = createEventDispatcher(); + let refPanel = null; @@ -40,17 +49,17 @@ } - { - if (target && refPanel) { - if (!refPanel.contains(target)) { - isOpen = false; - } + { + if (isOpen && !ref.contains(target) && !refPanel.contains(target)) { + isOpen = false; + dispatch('close'); } }} />