Skip to content

Commit f5e9934

Browse files
silentcloudbenjycui
authored andcommitted
fix: mask clicked causes below element events triggered, ref ant-desi… (#71)
* fix: mask clicked causes below element events triggered, ref ant-design/ant-design-mobile#1909 * add ua
1 parent 1dd782a commit f5e9934

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ const ALL_HANDLERS = ['onClick', 'onMouseDown', 'onTouchStart', 'onMouseEnter',
2525

2626
const IS_REACT_16 = !!createPortal;
2727

28+
const isMobile = typeof navigator !== 'undefined' && !!navigator.userAgent.match(
29+
/(Android|iPhone|iPad|iPod|iOS|UCWEB)/i
30+
);
31+
2832
const mixins = [];
2933

3034
if (!IS_REACT_16) {
@@ -163,7 +167,7 @@ const Trigger = createReactClass({
163167
triggerAfterPopupVisibleChange();
164168
}
165169

166-
// We must listen to `mousedown` or `touchstart`, edge case:
170+
// We must listen to `mousedown`, edge case:
167171
// https://github.com/ant-design/ant-design/issues/5804
168172
// https://github.com/react-component/calendar/issues/250
169173
// https://github.com/react-component/trigger/issues/50
@@ -175,10 +179,13 @@ const Trigger = createReactClass({
175179
'mousedown', this.onDocumentClick);
176180
}
177181
// always hide on mobile
178-
if (!this.touchOutsideHandler) {
182+
// `isMobile` fix: mask clicked will cause below element events triggered
183+
// https://github.com/ant-design/ant-design-mobile/issues/1909
184+
// https://github.com/ant-design/ant-design-mobile/issues/1928
185+
if (!this.touchOutsideHandler && isMobile) {
179186
currentDocument = currentDocument || props.getDocument();
180187
this.touchOutsideHandler = addEventListener(currentDocument,
181-
'touchstart', this.onDocumentClick);
188+
'click', this.onDocumentClick);
182189
}
183190
return;
184191
}

0 commit comments

Comments
 (0)