From 216e7003068c818eca078ff3ae2692439d86f930 Mon Sep 17 00:00:00 2001 From: Galina Teklyuk <54212063+lunaticenslaved@users.noreply.github.com> Date: Tue, 10 Sep 2024 13:01:38 +0300 Subject: [PATCH] fix(useFocusWithin): ignore blur event when window loses focus (#1836) --- src/hooks/useFocusWithin/useFocusWithin.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hooks/useFocusWithin/useFocusWithin.ts b/src/hooks/useFocusWithin/useFocusWithin.ts index 46e2185d02..3a66c97749 100644 --- a/src/hooks/useFocusWithin/useFocusWithin.ts +++ b/src/hooks/useFocusWithin/useFocusWithin.ts @@ -185,9 +185,10 @@ function useFocusEvents({ const onBlurHandler = React.useCallback( (event: React.FocusEvent) => { if ( - event.relatedTarget === null || - event.relatedTarget === document.body || - event.relatedTarget === (document as EventTarget) + document.activeElement !== event.target && + (event.relatedTarget === null || + event.relatedTarget === document.body || + event.relatedTarget === (document as EventTarget)) ) { onBlur(event); targetRef.current = null;