From dee36c056b7de0d7591650af55500fff11d462a9 Mon Sep 17 00:00:00 2001 From: Gerard Burns Date: Mon, 17 Oct 2022 19:58:43 +0100 Subject: [PATCH] Clicking the Toggle Button of an Open Action Menu Does Not Close It --- packages/bbui/src/Actions/click_outside.js | 6 +++--- packages/bbui/src/Popover/Popover.svelte | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/bbui/src/Actions/click_outside.js b/packages/bbui/src/Actions/click_outside.js index 49a15d36a3..7fd2879071 100644 --- a/packages/bbui/src/Actions/click_outside.js +++ b/packages/bbui/src/Actions/click_outside.js @@ -1,18 +1,18 @@ export default function clickOutside(element, callbackFunction) { function onClick(event) { if (!element.contains(event.target)) { - callbackFunction() + callbackFunction(event) } } - document.body.addEventListener("mousedown", onClick, true) + document.body.addEventListener("click", onClick, true) return { update(newCallbackFunction) { callbackFunction = newCallbackFunction }, destroy() { - document.body.removeEventListener("mousedown", onClick, true) + document.body.removeEventListener("click", onClick, true) }, } } diff --git a/packages/bbui/src/Popover/Popover.svelte b/packages/bbui/src/Popover/Popover.svelte index ded0ed6cfd..b81e76dc1f 100644 --- a/packages/bbui/src/Popover/Popover.svelte +++ b/packages/bbui/src/Popover/Popover.svelte @@ -33,6 +33,13 @@ open = false } + const handleOutsideClick = e => { + if (open) { + e.stopPropagation() + hide() + } + } + let open = null function handleEscape(e) { @@ -47,7 +54,7 @@