From 028ebdf39103e71351593f1380625102f63f6de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Malinowski?= Date: Sat, 6 Nov 2021 11:48:06 +0100 Subject: [PATCH] fix(ToolTip): ensure at most one ToolTip is open at the same time - a click event closes the tooltip if the target is not the tooltip or the tooltip icon. - the event is registered in the capture phase and a `setTimeout` is used to deal with edge cases in which a button is used to toggle the tooltip on or off. --- src/Tooltip/Tooltip.svelte | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Tooltip/Tooltip.svelte b/src/Tooltip/Tooltip.svelte index 08a4aa4f..b206c869 100644 --- a/src/Tooltip/Tooltip.svelte +++ b/src/Tooltip/Tooltip.svelte @@ -184,6 +184,13 @@ } } }}" + on:click|capture="{({ target }) => { + if (open && !ref.contains(target) && !refTooltip.contains(target)) { + setTimeout(() => { + open = false; + }); + } + }}" />