diff --git a/examples/nested.js b/examples/nested.js
index 84529e67..a205bf21 100644
--- a/examples/nested.js
+++ b/examples/nested.js
@@ -1,6 +1,7 @@
/* eslint no-console:0 */
import React from 'react';
+import ReactDOM from 'react-dom';
import Trigger from '../src';
import '../assets/index.less';
@@ -36,66 +37,96 @@ const popupBorderStyle = {
padding: 10,
};
-class Test extends React.Component {
- saveContainerRef = (node) => {
- this.containerInstanceNode = node;
- };
+const OuterContent = ({ getContainer }) => {
+ return ReactDOM.createPortal(
+
+ I am outer content
+
+
,
+ getContainer(),
+ );
+};
+
+const Test = () => {
+ const containerRef = React.useRef();
+ const outerDivRef = React.useRef();
- render() {
- const innerTrigger = (
-
-
+ const innerTrigger = (
+
+
+
containerRef.current}
+ popup={I am inner Trigger Popup
}
+ >
+
+ clickToShowInnerTrigger
+
+
+
+ );
+ return (
+
+
this.containerInstanceNode}
- popup={I am inner Trigger Popup
}
+ popup={
+
+ i am a click popup
+ outerDivRef.current} />
+
+ }
>
-
- clickToShowInnerTrigger
+
+ i am a hover popup }
+ >
+
+ trigger
+
+
- );
- return (
-
-
- i am a click popup
}
- >
-
- i am a hover popup}
- >
-
- trigger
-
-
-
-
-
-
-
-
- trigger
-
-
-
+
+
+
+ trigger
+
+
- );
- }
-}
+
+
+
+ );
+};
export default Test;
diff --git a/src/Popup/PopupInner.tsx b/src/Popup/PopupInner.tsx
index df24bd76..4cf10d5e 100644
--- a/src/Popup/PopupInner.tsx
+++ b/src/Popup/PopupInner.tsx
@@ -218,8 +218,8 @@ const PopupInner = React.forwardRef(
className={mergedClassName}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
- onMouseDown={onMouseDown}
- onTouchStart={onTouchStart}
+ onMouseDownCapture={onMouseDown}
+ onTouchStartCapture={onTouchStart}
style={{
...motionStyle,
...mergedStyle,
diff --git a/tests/basic.test.jsx b/tests/basic.test.jsx
index baecc375..dd6c737b 100644
--- a/tests/basic.test.jsx
+++ b/tests/basic.test.jsx
@@ -1,67 +1,13 @@
+/* eslint-disable max-classes-per-file */
+
import React from 'react';
+import ReactDOM from 'react-dom';
import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
import Portal from 'rc-util/lib/Portal';
import Trigger from '../src';
-
-const autoAdjustOverflow = {
- adjustX: 1,
- adjustY: 1,
-};
-
-const targetOffsetG = [0, 0];
-
-export const placementAlignMap = {
- left: {
- points: ['cr', 'cl'],
- overflow: autoAdjustOverflow,
- offset: [-3, 0],
- targetOffsetG,
- },
- right: {
- points: ['cl', 'cr'],
- overflow: autoAdjustOverflow,
- offset: [3, 0],
- targetOffsetG,
- },
- top: {
- points: ['bc', 'tc'],
- overflow: autoAdjustOverflow,
- offset: [0, -3],
- targetOffsetG,
- },
- bottom: {
- points: ['tc', 'bc'],
- overflow: autoAdjustOverflow,
- offset: [0, 3],
- targetOffsetG,
- },
- topLeft: {
- points: ['bl', 'tl'],
- overflow: autoAdjustOverflow,
- offset: [0, -3],
- targetOffsetG,
- },
- topRight: {
- points: ['br', 'tr'],
- overflow: autoAdjustOverflow,
- offset: [0, -3],
- targetOffsetG,
- },
- bottomRight: {
- points: ['tr', 'br'],
- overflow: autoAdjustOverflow,
- offset: [0, 3],
- targetOffsetG,
- },
- bottomLeft: {
- points: ['tl', 'bl'],
- overflow: autoAdjustOverflow,
- offset: [0, 3],
- targetOffsetG,
- },
-};
+import { placementAlignMap } from './util';
describe('Trigger.Basic', () => {
beforeEach(() => {
@@ -147,12 +93,7 @@ describe('Trigger.Basic', () => {
);
wrapper.trigger();
- expect(
- wrapper
- .find('Popup')
- .find('.x-content')
- .text(),
- ).toBe('tooltip2');
+ expect(wrapper.find('Popup').find('.x-content').text()).toBe('tooltip2');
wrapper.trigger();
expect(wrapper.isHidden()).toBeTruthy();
@@ -173,12 +114,7 @@ describe('Trigger.Basic', () => {
);
wrapper.trigger();
- expect(
- wrapper
- .find('Popup')
- .find('.x-content')
- .text(),
- ).toBe('tooltip3');
+ expect(wrapper.find('Popup').find('.x-content').text()).toBe('tooltip3');
wrapper.trigger();
expect(wrapper.isHidden()).toBeTruthy();
@@ -509,7 +445,7 @@ describe('Trigger.Basic', () => {
});
describe('stretch', () => {
- const createTrigger = stretch =>
+ const createTrigger = (stretch) =>
mount(
{
domSpy.mockRestore();
});
- ['width', 'height', 'minWidth', 'minHeight'].forEach(prop => {
+ ['width', 'height', 'minWidth', 'minHeight'].forEach((prop) => {
it(prop, () => {
const wrapper = createTrigger(prop);
@@ -643,7 +579,7 @@ describe('Trigger.Basic', () => {