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

Modern Event System: register onMouseEnter for portals #18720

Merged
merged 1 commit into from Apr 23, 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: 4 additions & 0 deletions packages/react-art/src/ReactARTHostConfig.js
Expand Up @@ -500,3 +500,7 @@ export function beforeActiveInstanceBlur() {
export function afterActiveInstanceBlur() {
// noop
}

export function preparePortalMount(portalInstance: any): void {
// noop
}
8 changes: 8 additions & 0 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Expand Up @@ -64,8 +64,10 @@ import {
enableSuspenseServerRenderer,
enableDeprecatedFlareAPI,
enableFundamentalAPI,
enableModernEventSystem,
} from 'shared/ReactFeatureFlags';
import {TOP_BEFORE_BLUR, TOP_AFTER_BLUR} from '../events/DOMTopLevelEventTypes';
import {listenToEvent} from '../events/DOMModernPluginEventSystem';

export type Type = string;
export type Props = {
Expand Down Expand Up @@ -1098,3 +1100,9 @@ export function makeOpaqueHydratingObject(
valueOf: attemptToReadValue,
};
}

export function preparePortalMount(portalInstance: Instance): void {
if (enableModernEventSystem) {
listenToEvent('onMouseEnter', portalInstance);
}
}
Expand Up @@ -239,4 +239,30 @@ describe('EnterLeaveEventPlugin', () => {

ReactDOM.render(<Parent />, container);
});

it('should work with portals outside of the root', () => {
const divRef = React.createRef();
const onMouseLeave = jest.fn();

function Component() {
return (
<div onMouseLeave={onMouseLeave}>
{ReactDOM.createPortal(<div ref={divRef} />, document.body)}
</div>
);
}

ReactDOM.render(<Component />, container);

// Leave from the portal div
divRef.current.dispatchEvent(
new MouseEvent('mouseout', {
bubbles: true,
cancelable: true,
relatedTarget: document.body,
}),
);

expect(onMouseLeave).toHaveBeenCalledTimes(1);
});
});
4 changes: 4 additions & 0 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Expand Up @@ -514,3 +514,7 @@ export function beforeActiveInstanceBlur() {
export function afterActiveInstanceBlur() {
// noop
}

export function preparePortalMount(portalInstance: Instance): void {
// noop
}
4 changes: 4 additions & 0 deletions packages/react-native-renderer/src/ReactNativeHostConfig.js
Expand Up @@ -562,3 +562,7 @@ export function beforeActiveInstanceBlur() {
export function afterActiveInstanceBlur() {
// noop
}

export function preparePortalMount(portalInstance: Instance): void {
// noop
}
4 changes: 4 additions & 0 deletions packages/react-noop-renderer/src/createReactNoop.js
Expand Up @@ -449,6 +449,10 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
afterActiveInstanceBlur() {
// NO-OP
},

preparePortalMount() {
// NO-OP
},
};

const hostConfig = useMutation
Expand Down
4 changes: 4 additions & 0 deletions packages/react-reconciler/src/ReactFiberCompleteWork.new.js
Expand Up @@ -82,6 +82,7 @@ import {
mountFundamentalComponent,
cloneFundamentalInstance,
shouldUpdateFundamentalComponent,
preparePortalMount,
} from './ReactFiberHostConfig';
import {
getRootHostContainer,
Expand Down Expand Up @@ -973,6 +974,9 @@ function completeWork(
case HostPortal:
popHostContainer(workInProgress);
updateHostContainer(workInProgress);
if (current === null) {
preparePortalMount(workInProgress.stateNode.containerInfo);
}
return null;
case ContextProvider:
// Pop provider fiber
Expand Down
4 changes: 4 additions & 0 deletions packages/react-reconciler/src/ReactFiberCompleteWork.old.js
Expand Up @@ -82,6 +82,7 @@ import {
mountFundamentalComponent,
cloneFundamentalInstance,
shouldUpdateFundamentalComponent,
preparePortalMount,
} from './ReactFiberHostConfig';
import {
getRootHostContainer,
Expand Down Expand Up @@ -973,6 +974,9 @@ function completeWork(
case HostPortal:
popHostContainer(workInProgress);
updateHostContainer(workInProgress);
if (current === null) {
preparePortalMount(workInProgress.stateNode.containerInfo);
}
return null;
case ContextProvider:
// Pop provider fiber
Expand Down
Expand Up @@ -83,6 +83,7 @@ export const makeClientIdInDEV = $$$hostConfig.makeClientIdInDEV;
export const makeServerId = $$$hostConfig.makeServerId;
export const beforeActiveInstanceBlur = $$$hostConfig.beforeActiveInstanceBlur;
export const afterActiveInstanceBlur = $$$hostConfig.afterActiveInstanceBlur;
export const preparePortalMount = $$$hostConfig.preparePortalMount;

// -------------------
// Mutation
Expand Down
4 changes: 4 additions & 0 deletions packages/react-test-renderer/src/ReactTestHostConfig.js
Expand Up @@ -435,3 +435,7 @@ export function beforeActiveInstanceBlur() {
export function afterActiveInstanceBlur() {
// noop
}

export function preparePortalMount(portalInstance: Instance): void {
// noop
}