Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further cleanup to before/after blur #18649

Merged
merged 1 commit into from Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/react-dom/src/client/ReactDOMComponent.js
Expand Up @@ -1355,10 +1355,6 @@ export function listenToEventResponderEventTypes(
const targetEventType = isPassive
? eventType
: eventType.substring(0, eventType.length - 7);
// We don't listen to this as we actually emulate it in the host config
if (targetEventType === 'beforeblur') {
continue;
}
if (!listenerMap.has(eventKey)) {
if (isPassive) {
const activeKey = targetEventType + '_active';
Expand Down
32 changes: 2 additions & 30 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Expand Up @@ -62,7 +62,6 @@ import {REACT_OPAQUE_ID_TYPE} from 'shared/ReactSymbols';
import {
mountEventResponder,
unmountEventResponder,
DEPRECATED_dispatchEventForResponderEventSystem,
} from '../events/DeprecatedDOMEventResponderSystem';
import {retryIfBlockedOn} from '../events/ReactDOMEventReplaying';

Expand All @@ -74,8 +73,6 @@ import {
enableScopeAPI,
} from 'shared/ReactFeatureFlags';
import {
RESPONDER_EVENT_SYSTEM,
IS_PASSIVE,
PLUGIN_EVENT_SYSTEM,
USE_EVENT_SYSTEM,
} from '../events/EventSystemFlags';
Expand Down Expand Up @@ -528,22 +525,9 @@ function createEvent(type: TopLevelType): Event {
}

function dispatchBeforeDetachedBlur(target: HTMLElement): void {
const targetInstance = getClosestInstanceFromNode(target);
((selectionInformation: any): SelectionInformation).activeElementDetached = target;

if (enableDeprecatedFlareAPI) {
DEPRECATED_dispatchEventForResponderEventSystem(
'beforeblur',
targetInstance,
({
target,
timeStamp: Date.now(),
}: any),
target,
RESPONDER_EVENT_SYSTEM | IS_PASSIVE,
);
}
if (enableUseEventAPI) {
if (enableDeprecatedFlareAPI || enableUseEventAPI) {
const event = createEvent(TOP_BEFORE_BLUR);
// Dispatch "beforeblur" directly on the target,
// so it gets picked up by the event system and
Expand All @@ -553,19 +537,7 @@ function dispatchBeforeDetachedBlur(target: HTMLElement): void {
}

function dispatchAfterDetachedBlur(target: HTMLElement): void {
if (enableDeprecatedFlareAPI) {
DEPRECATED_dispatchEventForResponderEventSystem(
'afterblur',
null,
({
relatedTarget: target,
timeStamp: Date.now(),
}: any),
target,
RESPONDER_EVENT_SYSTEM | IS_PASSIVE,
);
}
if (enableUseEventAPI) {
if (enableDeprecatedFlareAPI || enableUseEventAPI) {
const event = createEvent(TOP_AFTER_BLUR);
// So we know what was detached, make the relatedTarget the
// detached target on the "afterblur" event.
Expand Down
10 changes: 6 additions & 4 deletions packages/react-interactions/events/src/dom/DeprecatedFocus.js
Expand Up @@ -381,14 +381,13 @@ function dispatchAfterBlurWithinEvents(
state: FocusState,
) {
const pointerType = state.pointerType;
const target = ((state.focusTarget: any): Element | Document) || event.target;
const onAfterBlurWithin = (props.onAfterBlurWithin: any);
const relatedTarget = state.detachedTarget;
if (isFunction(onAfterBlurWithin)) {
if (isFunction(onAfterBlurWithin) && relatedTarget !== null) {
const syntheticEvent = createFocusEvent(
context,
'afterblurwithin',
target,
relatedTarget,
pointerType,
relatedTarget,
);
Expand Down Expand Up @@ -684,7 +683,10 @@ const focusWithinResponderImpl = {
): void {
if (event.type === 'afterblur') {
const detachedTarget = state.detachedTarget;
if (detachedTarget !== null && detachedTarget === event.target) {
if (
detachedTarget !== null &&
detachedTarget === event.nativeEvent.relatedTarget
) {
dispatchAfterBlurWithinEvents(context, event, props, state);
state.detachedTarget = null;
if (state.addedRootEvents) {
Expand Down