@rc-component/trigger
Advanced tools
Comparing version 1.13.0 to 1.13.1
@@ -13,3 +13,2 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; | ||
import isMobile from "rc-util/es/isMobile"; | ||
import warning from "rc-util/es/warning"; | ||
import * as React from 'react'; | ||
@@ -20,5 +19,6 @@ import TriggerContext from "./context"; | ||
import useWatch from "./hooks/useWatch"; | ||
import useWinClick from "./hooks/useWinClick"; | ||
import Popup from "./Popup"; | ||
import TriggerWrapper from "./TriggerWrapper"; | ||
import { getAlignPopupClassName, getMotion, getWin } from "./util"; | ||
import { getAlignPopupClassName, getMotion } from "./util"; | ||
export function generateTrigger() { | ||
@@ -330,46 +330,4 @@ var PortalComponent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Portal; | ||
// Click to hide is special action since click popup element should not hide | ||
React.useEffect(function () { | ||
if (clickToHide && popupEle && (!mask || maskClosable)) { | ||
var clickInside = false; | ||
useWinClick(mergedOpen, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen); | ||
// User may mouseDown inside and drag out of popup and mouse up | ||
// Record here to prevent close | ||
var onWindowMouseDown = function onWindowMouseDown(_ref) { | ||
var target = _ref.target; | ||
clickInside = inPopupOrChild(target); | ||
}; | ||
var onWindowClick = function onWindowClick(_ref2) { | ||
var target = _ref2.target; | ||
if (openRef.current && !clickInside && !inPopupOrChild(target)) { | ||
triggerOpen(false); | ||
} | ||
}; | ||
var win = getWin(popupEle); | ||
var targetRoot = targetEle === null || targetEle === void 0 ? void 0 : targetEle.getRootNode(); | ||
win.addEventListener('mousedown', onWindowMouseDown); | ||
win.addEventListener('click', onWindowClick); | ||
// shadow root | ||
var inShadow = targetRoot && targetRoot !== targetEle.ownerDocument; | ||
if (inShadow) { | ||
targetRoot.addEventListener('mousedown', onWindowMouseDown); | ||
targetRoot.addEventListener('click', onWindowClick); | ||
} | ||
// Warning if target and popup not in same root | ||
if (process.env.NODE_ENV !== 'production') { | ||
var popupRoot = popupEle.getRootNode(); | ||
warning(targetRoot === popupRoot, "trigger element and popup element should in same shadow root."); | ||
} | ||
return function () { | ||
win.removeEventListener('mousedown', onWindowMouseDown); | ||
win.removeEventListener('click', onWindowClick); | ||
if (inShadow) { | ||
targetRoot.removeEventListener('mousedown', onWindowMouseDown); | ||
targetRoot.removeEventListener('click', onWindowClick); | ||
} | ||
}; | ||
} | ||
}, [clickToHide, targetEle, popupEle, mask, maskClosable]); | ||
// ======================= Action: Hover ======================== | ||
@@ -376,0 +334,0 @@ var hoverToShow = showActions.has('hover'); |
@@ -21,3 +21,2 @@ "use strict"; | ||
var _isMobile = _interopRequireDefault(require("rc-util/lib/isMobile")); | ||
var _warning = _interopRequireDefault(require("rc-util/lib/warning")); | ||
var React = _interopRequireWildcard(require("react")); | ||
@@ -28,2 +27,3 @@ var _context = _interopRequireDefault(require("./context")); | ||
var _useWatch = _interopRequireDefault(require("./hooks/useWatch")); | ||
var _useWinClick = _interopRequireDefault(require("./hooks/useWinClick")); | ||
var _Popup = _interopRequireDefault(require("./Popup")); | ||
@@ -339,46 +339,4 @@ var _TriggerWrapper = _interopRequireDefault(require("./TriggerWrapper")); | ||
// Click to hide is special action since click popup element should not hide | ||
React.useEffect(function () { | ||
if (clickToHide && popupEle && (!mask || maskClosable)) { | ||
var clickInside = false; | ||
(0, _useWinClick.default)(mergedOpen, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen); | ||
// User may mouseDown inside and drag out of popup and mouse up | ||
// Record here to prevent close | ||
var onWindowMouseDown = function onWindowMouseDown(_ref) { | ||
var target = _ref.target; | ||
clickInside = inPopupOrChild(target); | ||
}; | ||
var onWindowClick = function onWindowClick(_ref2) { | ||
var target = _ref2.target; | ||
if (openRef.current && !clickInside && !inPopupOrChild(target)) { | ||
triggerOpen(false); | ||
} | ||
}; | ||
var win = (0, _util.getWin)(popupEle); | ||
var targetRoot = targetEle === null || targetEle === void 0 ? void 0 : targetEle.getRootNode(); | ||
win.addEventListener('mousedown', onWindowMouseDown); | ||
win.addEventListener('click', onWindowClick); | ||
// shadow root | ||
var inShadow = targetRoot && targetRoot !== targetEle.ownerDocument; | ||
if (inShadow) { | ||
targetRoot.addEventListener('mousedown', onWindowMouseDown); | ||
targetRoot.addEventListener('click', onWindowClick); | ||
} | ||
// Warning if target and popup not in same root | ||
if (process.env.NODE_ENV !== 'production') { | ||
var popupRoot = popupEle.getRootNode(); | ||
(0, _warning.default)(targetRoot === popupRoot, "trigger element and popup element should in same shadow root."); | ||
} | ||
return function () { | ||
win.removeEventListener('mousedown', onWindowMouseDown); | ||
win.removeEventListener('click', onWindowClick); | ||
if (inShadow) { | ||
targetRoot.removeEventListener('mousedown', onWindowMouseDown); | ||
targetRoot.removeEventListener('click', onWindowClick); | ||
} | ||
}; | ||
} | ||
}, [clickToHide, targetEle, popupEle, mask, maskClosable]); | ||
// ======================= Action: Hover ======================== | ||
@@ -385,0 +343,0 @@ var hoverToShow = showActions.has('hover'); |
{ | ||
"name": "@rc-component/trigger", | ||
"version": "1.13.0", | ||
"version": "1.13.1", | ||
"description": "base abstract trigger component for react", | ||
@@ -5,0 +5,0 @@ "engines": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
167860
63
3707