@rc-component/trigger 2.2.3 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,7 @@ export interface PopupProps {
11
11
  onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
12
12
  onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
13
13
  onPointerEnter?: React.MouseEventHandler<HTMLDivElement>;
14
+ onPointerDownCapture?: React.MouseEventHandler<HTMLDivElement>;
14
15
  zIndex?: number;
15
16
  mask?: boolean;
16
17
  onVisibleChanged: (visible: boolean) => void;
package/es/Popup/index.js CHANGED
@@ -35,6 +35,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
35
35
  onMouseEnter = props.onMouseEnter,
36
36
  onMouseLeave = props.onMouseLeave,
37
37
  onPointerEnter = props.onPointerEnter,
38
+ onPointerDownCapture = props.onPointerDownCapture,
38
39
  ready = props.ready,
39
40
  offsetX = props.offsetX,
40
41
  offsetY = props.offsetY,
@@ -167,7 +168,8 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
167
168
  onMouseEnter: onMouseEnter,
168
169
  onMouseLeave: onMouseLeave,
169
170
  onPointerEnter: onPointerEnter,
170
- onClick: onClick
171
+ onClick: onClick,
172
+ onPointerDownCapture: onPointerDownCapture
171
173
  }, arrow && /*#__PURE__*/React.createElement(Arrow, {
172
174
  prefixCls: prefixCls,
173
175
  arrow: arrow,
@@ -1 +1 @@
1
- export default function useWinClick(open: boolean, clickToHide: boolean, targetEle: HTMLElement, popupEle: HTMLElement, mask: boolean, maskClosable: boolean, inPopupOrChild: (target: EventTarget) => boolean, triggerOpen: (open: boolean) => void): void;
1
+ export default function useWinClick(open: boolean, clickToHide: boolean, targetEle: HTMLElement, popupEle: HTMLElement, mask: boolean, maskClosable: boolean, inPopupOrChild: (target: EventTarget) => boolean, triggerOpen: (open: boolean) => void): () => void;
@@ -5,17 +5,22 @@ import { getWin } from "../util";
5
5
  export default function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen) {
6
6
  var openRef = React.useRef(open);
7
7
  openRef.current = open;
8
+ var popupPointerDownRef = React.useRef(false);
8
9
 
9
10
  // Click to hide is special action since click popup element should not hide
10
11
  React.useEffect(function () {
11
12
  if (clickToHide && popupEle && (!mask || maskClosable)) {
13
+ var onPointerDown = function onPointerDown() {
14
+ popupPointerDownRef.current = false;
15
+ };
12
16
  var onTriggerClose = function onTriggerClose(e) {
13
17
  var _e$composedPath;
14
- if (openRef.current && !inPopupOrChild(((_e$composedPath = e.composedPath) === null || _e$composedPath === void 0 || (_e$composedPath = _e$composedPath.call(e)) === null || _e$composedPath === void 0 ? void 0 : _e$composedPath[0]) || e.target)) {
18
+ if (openRef.current && !inPopupOrChild(((_e$composedPath = e.composedPath) === null || _e$composedPath === void 0 || (_e$composedPath = _e$composedPath.call(e)) === null || _e$composedPath === void 0 ? void 0 : _e$composedPath[0]) || e.target) && !popupPointerDownRef.current) {
15
19
  triggerOpen(false);
16
20
  }
17
21
  };
18
22
  var win = getWin(popupEle);
23
+ win.addEventListener('pointerdown', onPointerDown, true);
19
24
  win.addEventListener('mousedown', onTriggerClose, true);
20
25
  win.addEventListener('contextmenu', onTriggerClose, true);
21
26
 
@@ -34,6 +39,7 @@ export default function useWinClick(open, clickToHide, targetEle, popupEle, mask
34
39
  warning(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
35
40
  }
36
41
  return function () {
42
+ win.removeEventListener('pointerdown', onPointerDown, true);
37
43
  win.removeEventListener('mousedown', onTriggerClose, true);
38
44
  win.removeEventListener('contextmenu', onTriggerClose, true);
39
45
  if (targetShadowRoot) {
@@ -43,4 +49,8 @@ export default function useWinClick(open, clickToHide, targetEle, popupEle, mask
43
49
  };
44
50
  }
45
51
  }, [clickToHide, targetEle, popupEle, mask, maskClosable]);
52
+ function onPopupPointerDown() {
53
+ popupPointerDownRef.current = true;
54
+ }
55
+ return onPopupPointerDown;
46
56
  }
package/es/index.js CHANGED
@@ -364,7 +364,7 @@ export function generateTrigger() {
364
364
  }
365
365
 
366
366
  // Click to hide is special action since click popup element should not hide
367
- useWinClick(mergedOpen, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen);
367
+ var onPopupPointerDown = useWinClick(mergedOpen, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen);
368
368
 
369
369
  // ======================= Action: Hover ========================
370
370
  var hoverToShow = showActions.has('hover');
@@ -493,7 +493,8 @@ export function generateTrigger() {
493
493
  fresh: fresh
494
494
  // Click
495
495
  ,
496
- onClick: onPopupClick
496
+ onClick: onPopupClick,
497
+ onPointerDownCapture: onPopupPointerDown
497
498
  // Mask
498
499
  ,
499
500
  mask: mask
@@ -11,6 +11,7 @@ export interface PopupProps {
11
11
  onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
12
12
  onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
13
13
  onPointerEnter?: React.MouseEventHandler<HTMLDivElement>;
14
+ onPointerDownCapture?: React.MouseEventHandler<HTMLDivElement>;
14
15
  zIndex?: number;
15
16
  mask?: boolean;
16
17
  onVisibleChanged: (visible: boolean) => void;
@@ -43,6 +43,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
43
43
  onMouseEnter = props.onMouseEnter,
44
44
  onMouseLeave = props.onMouseLeave,
45
45
  onPointerEnter = props.onPointerEnter,
46
+ onPointerDownCapture = props.onPointerDownCapture,
46
47
  ready = props.ready,
47
48
  offsetX = props.offsetX,
48
49
  offsetY = props.offsetY,
@@ -175,7 +176,8 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
175
176
  onMouseEnter: onMouseEnter,
176
177
  onMouseLeave: onMouseLeave,
177
178
  onPointerEnter: onPointerEnter,
178
- onClick: onClick
179
+ onClick: onClick,
180
+ onPointerDownCapture: onPointerDownCapture
179
181
  }, arrow && /*#__PURE__*/React.createElement(_Arrow.default, {
180
182
  prefixCls: prefixCls,
181
183
  arrow: arrow,
@@ -1 +1 @@
1
- export default function useWinClick(open: boolean, clickToHide: boolean, targetEle: HTMLElement, popupEle: HTMLElement, mask: boolean, maskClosable: boolean, inPopupOrChild: (target: EventTarget) => boolean, triggerOpen: (open: boolean) => void): void;
1
+ export default function useWinClick(open: boolean, clickToHide: boolean, targetEle: HTMLElement, popupEle: HTMLElement, mask: boolean, maskClosable: boolean, inPopupOrChild: (target: EventTarget) => boolean, triggerOpen: (open: boolean) => void): () => void;
@@ -12,17 +12,22 @@ var _util = require("../util");
12
12
  function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen) {
13
13
  var openRef = React.useRef(open);
14
14
  openRef.current = open;
15
+ var popupPointerDownRef = React.useRef(false);
15
16
 
16
17
  // Click to hide is special action since click popup element should not hide
17
18
  React.useEffect(function () {
18
19
  if (clickToHide && popupEle && (!mask || maskClosable)) {
20
+ var onPointerDown = function onPointerDown() {
21
+ popupPointerDownRef.current = false;
22
+ };
19
23
  var onTriggerClose = function onTriggerClose(e) {
20
24
  var _e$composedPath;
21
- if (openRef.current && !inPopupOrChild(((_e$composedPath = e.composedPath) === null || _e$composedPath === void 0 || (_e$composedPath = _e$composedPath.call(e)) === null || _e$composedPath === void 0 ? void 0 : _e$composedPath[0]) || e.target)) {
25
+ if (openRef.current && !inPopupOrChild(((_e$composedPath = e.composedPath) === null || _e$composedPath === void 0 || (_e$composedPath = _e$composedPath.call(e)) === null || _e$composedPath === void 0 ? void 0 : _e$composedPath[0]) || e.target) && !popupPointerDownRef.current) {
22
26
  triggerOpen(false);
23
27
  }
24
28
  };
25
29
  var win = (0, _util.getWin)(popupEle);
30
+ win.addEventListener('pointerdown', onPointerDown, true);
26
31
  win.addEventListener('mousedown', onTriggerClose, true);
27
32
  win.addEventListener('contextmenu', onTriggerClose, true);
28
33
 
@@ -41,6 +46,7 @@ function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable,
41
46
  (0, _warning.warning)(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
42
47
  }
43
48
  return function () {
49
+ win.removeEventListener('pointerdown', onPointerDown, true);
44
50
  win.removeEventListener('mousedown', onTriggerClose, true);
45
51
  win.removeEventListener('contextmenu', onTriggerClose, true);
46
52
  if (targetShadowRoot) {
@@ -50,4 +56,8 @@ function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable,
50
56
  };
51
57
  }
52
58
  }, [clickToHide, targetEle, popupEle, mask, maskClosable]);
59
+ function onPopupPointerDown() {
60
+ popupPointerDownRef.current = true;
61
+ }
62
+ return onPopupPointerDown;
53
63
  }
package/lib/index.js CHANGED
@@ -372,7 +372,7 @@ function generateTrigger() {
372
372
  }
373
373
 
374
374
  // Click to hide is special action since click popup element should not hide
375
- (0, _useWinClick.default)(mergedOpen, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen);
375
+ var onPopupPointerDown = (0, _useWinClick.default)(mergedOpen, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen);
376
376
 
377
377
  // ======================= Action: Hover ========================
378
378
  var hoverToShow = showActions.has('hover');
@@ -501,7 +501,8 @@ function generateTrigger() {
501
501
  fresh: fresh
502
502
  // Click
503
503
  ,
504
- onClick: onPopupClick
504
+ onClick: onPopupClick,
505
+ onPointerDownCapture: onPopupPointerDown
505
506
  // Mask
506
507
  ,
507
508
  mask: mask
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/trigger",
3
- "version": "2.2.3",
3
+ "version": "2.2.5",
4
4
  "description": "base abstract trigger component for react",
5
5
  "engines": {
6
6
  "node": ">=8.x"