Skip to content

Commit

Permalink
Add guard around FocusWithin responder root events (facebook#18080)
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed Feb 19, 2020
1 parent 1000f61 commit b6c94d6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/react-interactions/events/src/dom/Focus.js
Expand Up @@ -36,7 +36,7 @@ type FocusState = {
isFocused: boolean,
isFocusVisible: boolean,
pointerType: PointerType,
...
addedRootEvents?: boolean,
};

type FocusProps = {
Expand Down Expand Up @@ -416,6 +416,7 @@ const focusResponderImpl = {
isFocused: false,
isFocusVisible: false,
pointerType: '',
addedRootEvents: false,
};
},
onMount() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
},
Expand Down

0 comments on commit b6c94d6

Please sign in to comment.