From b6c94d636cb33a265671b864b97870da38d97207 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 19 Feb 2020 18:32:18 +0000 Subject: [PATCH] Add guard around FocusWithin responder root events (#18080) --- packages/react-interactions/events/src/dom/Focus.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/react-interactions/events/src/dom/Focus.js b/packages/react-interactions/events/src/dom/Focus.js index d97723dfe6201..f4f5e4a0fedc3 100644 --- a/packages/react-interactions/events/src/dom/Focus.js +++ b/packages/react-interactions/events/src/dom/Focus.js @@ -36,7 +36,7 @@ type FocusState = { isFocused: boolean, isFocusVisible: boolean, pointerType: PointerType, - ... + addedRootEvents?: boolean, }; type FocusProps = { @@ -416,6 +416,7 @@ const focusResponderImpl = { isFocused: false, isFocusVisible: false, pointerType: '', + addedRootEvents: false, }; }, onMount() { @@ -622,7 +623,10 @@ const focusWithinResponderImpl = { onBeforeBlurWithin, DiscreteEvent, ); - context.addRootEventTypes(rootEventTypes); + if (!state.addedRootEvents) { + state.addedRootEvents = true; + context.addRootEventTypes(rootEventTypes); + } } else { // We want to propagate to next focusWithin responder // if this responder doesn't handle beforeblur @@ -660,7 +664,10 @@ const focusWithinResponderImpl = { if (detachedTarget !== null && detachedTarget === event.target) { dispatchBlurWithinEvents(context, event, props, state); state.detachedTarget = null; - context.removeRootEventTypes(rootEventTypes); + if (state.addedRootEvents) { + state.addedRootEvents = false; + context.removeRootEventTypes(rootEventTypes); + } } } },