Skip to content

Commit faea604

Browse files
committed
feat: add event listener option
1 parent 92793b4 commit faea604

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

examples/auto-close.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* eslint no-console:0 */
2+
3+
import React from 'react';
4+
import Trigger from '../src';
5+
import '../assets/index.less';
6+
7+
const builtinPlacements = {
8+
left: {
9+
points: ['cr', 'cl'],
10+
},
11+
right: {
12+
points: ['cl', 'cr'],
13+
},
14+
top: {
15+
points: ['bc', 'tc'],
16+
},
17+
bottom: {
18+
points: ['tc', 'bc'],
19+
},
20+
topLeft: {
21+
points: ['bl', 'tl'],
22+
},
23+
topRight: {
24+
points: ['br', 'tr'],
25+
},
26+
bottomRight: {
27+
points: ['tr', 'br'],
28+
},
29+
bottomLeft: {
30+
points: ['tl', 'bl'],
31+
},
32+
};
33+
34+
const popupBorderStyle = {
35+
border: '1px solid red',
36+
padding: 10,
37+
background: 'rgba(255, 0, 0, 0.1)',
38+
};
39+
40+
class Test extends React.Component {
41+
render() {
42+
return (
43+
<div style={{ margin: 200 }}>
44+
<div onMouseDown={e => e.stopPropagation()}>
45+
<Trigger
46+
popupPlacement="right"
47+
action={['click']}
48+
builtinPlacements={builtinPlacements}
49+
popup={
50+
<div>popup content</div>
51+
}
52+
//effect on react 17
53+
triggerEventListenerOption={{
54+
capture: true
55+
}}
56+
>
57+
<span>Click Me1</span>
58+
</Trigger>
59+
</div>
60+
<div onMouseDown={e => e.stopPropagation()}>
61+
<Trigger
62+
popupPlacement="right"
63+
action={['click']}
64+
builtinPlacements={builtinPlacements}
65+
popup={
66+
<div>popup content2 </div>
67+
}
68+
>
69+
<span>Click Me2</span>
70+
</Trigger>
71+
</div>
72+
</div>
73+
);
74+
}
75+
}
76+
77+
export default Test;

src/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export interface TriggerProps {
111111
/** @private Bump fixed position at bottom in mobile.
112112
* This is internal usage currently, do not use in your prod */
113113
mobile?: MobileConfig;
114+
triggerEventListenerOption?: object
114115
}
115116

116117
interface TriggerState {
@@ -150,6 +151,7 @@ export function generateTrigger(
150151
showAction: [],
151152
hideAction: [],
152153
autoDestroy: false,
154+
triggerEventListenerOption: {}
153155
};
154156

155157
popupRef = React.createRef<PopupInnerRef>();
@@ -207,6 +209,7 @@ export function generateTrigger(
207209
componentDidUpdate() {
208210
const { props } = this;
209211
const { state } = this;
212+
const { triggerEventListenerOption = {} } = props
210213

211214
// We must listen to `mousedown` or `touchstart`, edge case:
212215
// https://github.com/ant-design/ant-design/issues/5804
@@ -223,6 +226,7 @@ export function generateTrigger(
223226
currentDocument,
224227
'mousedown',
225228
this.onDocumentClick,
229+
triggerEventListenerOption
226230
);
227231
}
228232
// always hide on mobile
@@ -233,6 +237,7 @@ export function generateTrigger(
233237
currentDocument,
234238
'touchstart',
235239
this.onDocumentClick,
240+
triggerEventListenerOption
236241
);
237242
}
238243
// close popup when trigger type contains 'onContextMenu' and document is scrolling.
@@ -243,6 +248,7 @@ export function generateTrigger(
243248
currentDocument,
244249
'scroll',
245250
this.onContextMenuClose,
251+
triggerEventListenerOption
246252
);
247253
}
248254
// close popup when trigger type contains 'onContextMenu' and window is blur.

0 commit comments

Comments
 (0)