@rc-component/trigger 1.15.1 → 1.15.2

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.
@@ -1 +1 @@
1
- export default function useWatch(open: boolean, target: HTMLElement, popup: HTMLElement, onAlign: VoidFunction): void;
1
+ export default function useWatch(open: boolean, target: HTMLElement, popup: HTMLElement, onAlign: VoidFunction, onScroll: VoidFunction): void;
@@ -1,7 +1,7 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
3
3
  import { collectScroller, getWin } from "../util";
4
- export default function useWatch(open, target, popup, onAlign) {
4
+ export default function useWatch(open, target, popup, onAlign, onScroll) {
5
5
  useLayoutEffect(function () {
6
6
  if (open && target && popup) {
7
7
  var targetElement = target;
@@ -12,6 +12,7 @@ export default function useWatch(open, target, popup, onAlign) {
12
12
  var mergedList = new Set([win].concat(_toConsumableArray(targetScrollList), _toConsumableArray(popupScrollList)));
13
13
  function notifyScroll() {
14
14
  onAlign();
15
+ onScroll();
15
16
  }
16
17
  mergedList.forEach(function (scroller) {
17
18
  scroller.addEventListener('scroll', notifyScroll, {
package/es/index.js CHANGED
@@ -226,12 +226,23 @@ export function generateTrigger() {
226
226
  scaleY = _useAlign2[8],
227
227
  alignInfo = _useAlign2[9],
228
228
  onAlign = _useAlign2[10];
229
+ var _useAction = useAction(mobile, action, showAction, hideAction),
230
+ _useAction2 = _slicedToArray(_useAction, 2),
231
+ showActions = _useAction2[0],
232
+ hideActions = _useAction2[1];
233
+ var clickToShow = showActions.has('click');
234
+ var clickToHide = hideActions.has('click') || hideActions.has('contextMenu');
229
235
  var triggerAlign = useEvent(function () {
230
236
  if (!inMotion) {
231
237
  onAlign();
232
238
  }
233
239
  });
234
- useWatch(mergedOpen, targetEle, popupEle, triggerAlign);
240
+ var onScroll = function onScroll() {
241
+ if (openRef.current && alignPoint && clickToHide) {
242
+ triggerOpen(false);
243
+ }
244
+ };
245
+ useWatch(mergedOpen, targetEle, popupEle, triggerAlign, onScroll);
235
246
  useLayoutEffect(function () {
236
247
  triggerAlign();
237
248
  }, [mousePos, popupPlacement]);
@@ -294,11 +305,6 @@ export function generateTrigger() {
294
305
  };
295
306
 
296
307
  // =========================== Action ===========================
297
- var _useAction = useAction(mobile, action, showAction, hideAction),
298
- _useAction2 = _slicedToArray(_useAction, 2),
299
- showActions = _useAction2[0],
300
- hideActions = _useAction2[1];
301
-
302
308
  /**
303
309
  * Util wrapper for trigger action
304
310
  */
@@ -317,8 +323,6 @@ export function generateTrigger() {
317
323
  }
318
324
 
319
325
  // ======================= Action: Click ========================
320
- var clickToShow = showActions.has('click');
321
- var clickToHide = hideActions.has('click') || hideActions.has('contextMenu');
322
326
  if (clickToShow || clickToHide) {
323
327
  cloneProps.onClick = function (event) {
324
328
  var _originChildProps$onC;
@@ -1 +1 @@
1
- export default function useWatch(open: boolean, target: HTMLElement, popup: HTMLElement, onAlign: VoidFunction): void;
1
+ export default function useWatch(open: boolean, target: HTMLElement, popup: HTMLElement, onAlign: VoidFunction, onScroll: VoidFunction): void;
@@ -8,7 +8,7 @@ exports.default = useWatch;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _useLayoutEffect = _interopRequireDefault(require("rc-util/lib/hooks/useLayoutEffect"));
10
10
  var _util = require("../util");
11
- function useWatch(open, target, popup, onAlign) {
11
+ function useWatch(open, target, popup, onAlign, onScroll) {
12
12
  (0, _useLayoutEffect.default)(function () {
13
13
  if (open && target && popup) {
14
14
  var targetElement = target;
@@ -19,6 +19,7 @@ function useWatch(open, target, popup, onAlign) {
19
19
  var mergedList = new Set([win].concat((0, _toConsumableArray2.default)(targetScrollList), (0, _toConsumableArray2.default)(popupScrollList)));
20
20
  function notifyScroll() {
21
21
  onAlign();
22
+ onScroll();
22
23
  }
23
24
  mergedList.forEach(function (scroller) {
24
25
  scroller.addEventListener('scroll', notifyScroll, {
package/lib/index.js CHANGED
@@ -236,12 +236,23 @@ function generateTrigger() {
236
236
  scaleY = _useAlign2[8],
237
237
  alignInfo = _useAlign2[9],
238
238
  onAlign = _useAlign2[10];
239
+ var _useAction = (0, _useAction3.default)(mobile, action, showAction, hideAction),
240
+ _useAction2 = (0, _slicedToArray2.default)(_useAction, 2),
241
+ showActions = _useAction2[0],
242
+ hideActions = _useAction2[1];
243
+ var clickToShow = showActions.has('click');
244
+ var clickToHide = hideActions.has('click') || hideActions.has('contextMenu');
239
245
  var triggerAlign = (0, _useEvent.default)(function () {
240
246
  if (!inMotion) {
241
247
  onAlign();
242
248
  }
243
249
  });
244
- (0, _useWatch.default)(mergedOpen, targetEle, popupEle, triggerAlign);
250
+ var onScroll = function onScroll() {
251
+ if (openRef.current && alignPoint && clickToHide) {
252
+ triggerOpen(false);
253
+ }
254
+ };
255
+ (0, _useWatch.default)(mergedOpen, targetEle, popupEle, triggerAlign, onScroll);
245
256
  (0, _useLayoutEffect.default)(function () {
246
257
  triggerAlign();
247
258
  }, [mousePos, popupPlacement]);
@@ -304,11 +315,6 @@ function generateTrigger() {
304
315
  };
305
316
 
306
317
  // =========================== Action ===========================
307
- var _useAction = (0, _useAction3.default)(mobile, action, showAction, hideAction),
308
- _useAction2 = (0, _slicedToArray2.default)(_useAction, 2),
309
- showActions = _useAction2[0],
310
- hideActions = _useAction2[1];
311
-
312
318
  /**
313
319
  * Util wrapper for trigger action
314
320
  */
@@ -327,8 +333,6 @@ function generateTrigger() {
327
333
  }
328
334
 
329
335
  // ======================= Action: Click ========================
330
- var clickToShow = showActions.has('click');
331
- var clickToHide = hideActions.has('click') || hideActions.has('contextMenu');
332
336
  if (clickToShow || clickToHide) {
333
337
  cloneProps.onClick = function (event) {
334
338
  var _originChildProps$onC;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/trigger",
3
- "version": "1.15.1",
3
+ "version": "1.15.2",
4
4
  "description": "base abstract trigger component for react",
5
5
  "engines": {
6
6
  "node": ">=8.x"