From fb9ab1452fe82246a0785cdb85cb8116bf51bb07 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Wed, 21 Jun 2023 12:14:15 +0100 Subject: [PATCH] Update listener options on useDismissable --- src/useDismissable.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/useDismissable.ts b/src/useDismissable.ts index 12ba5e8..36db8da 100644 --- a/src/useDismissable.ts +++ b/src/useDismissable.ts @@ -87,24 +87,27 @@ export function useDismissable( } } + const opts = { capture: true } as any; + const touchOpts = { capture: true, passive: false } as any; + if (focusLoss) { - root.addEventListener('focusout', onFocusOut, true); - root.addEventListener('focusin', onFocusIn, true); + root.addEventListener('focusout', onFocusOut, opts); + root.addEventListener('focusin', onFocusIn, opts); } - root.addEventListener('click', onClick, true); - root.addEventListener('touchstart', onClick, true); - root.addEventListener('keydown', onKey, true); + root.addEventListener('click', onClick, opts); + root.addEventListener('touchstart', onClick, touchOpts); + root.addEventListener('keydown', onKey, opts); return () => { if (focusLoss) { - root.removeEventListener('focusout', onFocusOut, true); - root.removeEventListener('focusin', onFocusIn, true); + root.removeEventListener('focusout', onFocusOut, opts); + root.removeEventListener('focusin', onFocusIn, opts); } - root.removeEventListener('click', onClick, true); - root.removeEventListener('touchstart', onClick, true); - root.removeEventListener('keydown', onKey, true); + root.removeEventListener('click', onClick, opts); + root.removeEventListener('touchstart', onClick, touchOpts); + root.removeEventListener('keydown', onKey, opts); }; }, [ref.current, hasPriority, disabled, focusLoss]); } -- knotmirror 0.0.1