From 1bc0e02ab25d6fbb900896394de59da3fe3c2916 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 10 Jul 2024 07:59:49 -0500 Subject: [PATCH] fix(react): use capture phase instead of bubble phase for esc keypress on Tooltip (#1569) --- packages/react/src/components/Tooltip/index.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/react/src/components/Tooltip/index.tsx b/packages/react/src/components/Tooltip/index.tsx index eabb35bb8..ce90d9cce 100644 --- a/packages/react/src/components/Tooltip/index.tsx +++ b/packages/react/src/components/Tooltip/index.tsx @@ -136,13 +136,17 @@ export default function Tooltip({ const targetElement = document.body; if (showTooltip) { - targetElement.addEventListener('keyup', handleEscape); + targetElement.addEventListener('keyup', handleEscape, { capture: true }); } else { - targetElement.removeEventListener('keyup', handleEscape); + targetElement.removeEventListener('keyup', handleEscape, { + capture: true + }); } return () => { - targetElement.removeEventListener('keyup', handleEscape); + targetElement.removeEventListener('keyup', handleEscape, { + capture: true + }); }; }, [showTooltip]);