You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

730 lines
22 KiB

  1. import _extends from 'babel-runtime/helpers/extends';
  2. import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
  3. import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
  4. import _inherits from 'babel-runtime/helpers/inherits';
  5. import React from 'react';
  6. import PropTypes from 'prop-types';
  7. import { findDOMNode, createPortal } from 'react-dom';
  8. import { polyfill } from 'react-lifecycles-compat';
  9. import contains from 'rc-util/es/Dom/contains';
  10. import addEventListener from 'rc-util/es/Dom/addEventListener';
  11. import ContainerRender from 'rc-util/es/ContainerRender';
  12. import Portal from 'rc-util/es/Portal';
  13. import classNames from 'classnames';
  14. import { getAlignFromPlacement, getAlignPopupClassName } from './utils';
  15. import Popup from './Popup';
  16. function noop() {}
  17. function returnEmptyString() {
  18. return '';
  19. }
  20. function returnDocument() {
  21. return window.document;
  22. }
  23. var ALL_HANDLERS = ['onClick', 'onMouseDown', 'onTouchStart', 'onMouseEnter', 'onMouseLeave', 'onFocus', 'onBlur', 'onContextMenu'];
  24. var IS_REACT_16 = !!createPortal;
  25. var contextTypes = {
  26. rcTrigger: PropTypes.shape({
  27. onPopupMouseDown: PropTypes.func
  28. })
  29. };
  30. var Trigger = function (_React$Component) {
  31. _inherits(Trigger, _React$Component);
  32. function Trigger(props) {
  33. _classCallCheck(this, Trigger);
  34. var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
  35. _initialiseProps.call(_this);
  36. var popupVisible = void 0;
  37. if ('popupVisible' in props) {
  38. popupVisible = !!props.popupVisible;
  39. } else {
  40. popupVisible = !!props.defaultPopupVisible;
  41. }
  42. _this.state = {
  43. prevPopupVisible: popupVisible,
  44. popupVisible: popupVisible
  45. };
  46. ALL_HANDLERS.forEach(function (h) {
  47. _this['fire' + h] = function (e) {
  48. _this.fireEvents(h, e);
  49. };
  50. });
  51. return _this;
  52. }
  53. Trigger.prototype.getChildContext = function getChildContext() {
  54. return {
  55. rcTrigger: {
  56. onPopupMouseDown: this.onPopupMouseDown
  57. }
  58. };
  59. };
  60. Trigger.prototype.componentDidMount = function componentDidMount() {
  61. this.componentDidUpdate({}, {
  62. popupVisible: this.state.popupVisible
  63. });
  64. };
  65. Trigger.prototype.componentDidUpdate = function componentDidUpdate(_, prevState) {
  66. var props = this.props;
  67. var state = this.state;
  68. var triggerAfterPopupVisibleChange = function triggerAfterPopupVisibleChange() {
  69. if (prevState.popupVisible !== state.popupVisible) {
  70. props.afterPopupVisibleChange(state.popupVisible);
  71. }
  72. };
  73. if (!IS_REACT_16) {
  74. this.renderComponent(null, triggerAfterPopupVisibleChange);
  75. }
  76. // We must listen to `mousedown` or `touchstart`, edge case:
  77. // https://github.com/ant-design/ant-design/issues/5804
  78. // https://github.com/react-component/calendar/issues/250
  79. // https://github.com/react-component/trigger/issues/50
  80. if (state.popupVisible) {
  81. var currentDocument = void 0;
  82. if (!this.clickOutsideHandler && (this.isClickToHide() || this.isContextMenuToShow())) {
  83. currentDocument = props.getDocument();
  84. this.clickOutsideHandler = addEventListener(currentDocument, 'mousedown', this.onDocumentClick);
  85. }
  86. // always hide on mobile
  87. if (!this.touchOutsideHandler) {
  88. currentDocument = currentDocument || props.getDocument();
  89. this.touchOutsideHandler = addEventListener(currentDocument, 'touchstart', this.onDocumentClick);
  90. }
  91. // close popup when trigger type contains 'onContextMenu' and document is scrolling.
  92. if (!this.contextMenuOutsideHandler1 && this.isContextMenuToShow()) {
  93. currentDocument = currentDocument || props.getDocument();
  94. this.contextMenuOutsideHandler1 = addEventListener(currentDocument, 'scroll', this.onContextMenuClose);
  95. }
  96. // close popup when trigger type contains 'onContextMenu' and window is blur.
  97. if (!this.contextMenuOutsideHandler2 && this.isContextMenuToShow()) {
  98. this.contextMenuOutsideHandler2 = addEventListener(window, 'blur', this.onContextMenuClose);
  99. }
  100. return;
  101. }
  102. this.clearOutsideHandler();
  103. };
  104. Trigger.prototype.componentWillUnmount = function componentWillUnmount() {
  105. this.clearDelayTimer();
  106. this.clearOutsideHandler();
  107. clearTimeout(this.mouseDownTimeout);
  108. };
  109. Trigger.getDerivedStateFromProps = function getDerivedStateFromProps(_ref, prevState) {
  110. var popupVisible = _ref.popupVisible;
  111. var newState = {};
  112. if (popupVisible !== undefined && prevState.popupVisible !== popupVisible) {
  113. newState.popupVisible = popupVisible;
  114. newState.prevPopupVisible = prevState.popupVisible;
  115. }
  116. return newState;
  117. };
  118. Trigger.prototype.getPopupDomNode = function getPopupDomNode() {
  119. // for test
  120. if (this._component && this._component.getPopupDomNode) {
  121. return this._component.getPopupDomNode();
  122. }
  123. return null;
  124. };
  125. Trigger.prototype.getPopupAlign = function getPopupAlign() {
  126. var props = this.props;
  127. var popupPlacement = props.popupPlacement,
  128. popupAlign = props.popupAlign,
  129. builtinPlacements = props.builtinPlacements;
  130. if (popupPlacement && builtinPlacements) {
  131. return getAlignFromPlacement(builtinPlacements, popupPlacement, popupAlign);
  132. }
  133. return popupAlign;
  134. };
  135. /**
  136. * @param popupVisible Show or not the popup element
  137. * @param event SyntheticEvent, used for `pointAlign`
  138. */
  139. Trigger.prototype.setPopupVisible = function setPopupVisible(popupVisible, event) {
  140. var alignPoint = this.props.alignPoint;
  141. var prevPopupVisible = this.state.popupVisible;
  142. this.clearDelayTimer();
  143. if (prevPopupVisible !== popupVisible) {
  144. if (!('popupVisible' in this.props)) {
  145. this.setState({ popupVisible: popupVisible, prevPopupVisible: prevPopupVisible });
  146. }
  147. this.props.onPopupVisibleChange(popupVisible);
  148. }
  149. // Always record the point position since mouseEnterDelay will delay the show
  150. if (alignPoint && event) {
  151. this.setPoint(event);
  152. }
  153. };
  154. Trigger.prototype.delaySetPopupVisible = function delaySetPopupVisible(visible, delayS, event) {
  155. var _this2 = this;
  156. var delay = delayS * 1000;
  157. this.clearDelayTimer();
  158. if (delay) {
  159. var point = event ? { pageX: event.pageX, pageY: event.pageY } : null;
  160. this.delayTimer = setTimeout(function () {
  161. _this2.setPopupVisible(visible, point);
  162. _this2.clearDelayTimer();
  163. }, delay);
  164. } else {
  165. this.setPopupVisible(visible, event);
  166. }
  167. };
  168. Trigger.prototype.clearDelayTimer = function clearDelayTimer() {
  169. if (this.delayTimer) {
  170. clearTimeout(this.delayTimer);
  171. this.delayTimer = null;
  172. }
  173. };
  174. Trigger.prototype.clearOutsideHandler = function clearOutsideHandler() {
  175. if (this.clickOutsideHandler) {
  176. this.clickOutsideHandler.remove();
  177. this.clickOutsideHandler = null;
  178. }
  179. if (this.contextMenuOutsideHandler1) {
  180. this.contextMenuOutsideHandler1.remove();
  181. this.contextMenuOutsideHandler1 = null;
  182. }
  183. if (this.contextMenuOutsideHandler2) {
  184. this.contextMenuOutsideHandler2.remove();
  185. this.contextMenuOutsideHandler2 = null;
  186. }
  187. if (this.touchOutsideHandler) {
  188. this.touchOutsideHandler.remove();
  189. this.touchOutsideHandler = null;
  190. }
  191. };
  192. Trigger.prototype.createTwoChains = function createTwoChains(event) {
  193. var childPros = this.props.children.props;
  194. var props = this.props;
  195. if (childPros[event] && props[event]) {
  196. return this['fire' + event];
  197. }
  198. return childPros[event] || props[event];
  199. };
  200. Trigger.prototype.isClickToShow = function isClickToShow() {
  201. var _props = this.props,
  202. action = _props.action,
  203. showAction = _props.showAction;
  204. return action.indexOf('click') !== -1 || showAction.indexOf('click') !== -1;
  205. };
  206. Trigger.prototype.isContextMenuToShow = function isContextMenuToShow() {
  207. var _props2 = this.props,
  208. action = _props2.action,
  209. showAction = _props2.showAction;
  210. return action.indexOf('contextMenu') !== -1 || showAction.indexOf('contextMenu') !== -1;
  211. };
  212. Trigger.prototype.isClickToHide = function isClickToHide() {
  213. var _props3 = this.props,
  214. action = _props3.action,
  215. hideAction = _props3.hideAction;
  216. return action.indexOf('click') !== -1 || hideAction.indexOf('click') !== -1;
  217. };
  218. Trigger.prototype.isMouseEnterToShow = function isMouseEnterToShow() {
  219. var _props4 = this.props,
  220. action = _props4.action,
  221. showAction = _props4.showAction;
  222. return action.indexOf('hover') !== -1 || showAction.indexOf('mouseEnter') !== -1;
  223. };
  224. Trigger.prototype.isMouseLeaveToHide = function isMouseLeaveToHide() {
  225. var _props5 = this.props,
  226. action = _props5.action,
  227. hideAction = _props5.hideAction;
  228. return action.indexOf('hover') !== -1 || hideAction.indexOf('mouseLeave') !== -1;
  229. };
  230. Trigger.prototype.isFocusToShow = function isFocusToShow() {
  231. var _props6 = this.props,
  232. action = _props6.action,
  233. showAction = _props6.showAction;
  234. return action.indexOf('focus') !== -1 || showAction.indexOf('focus') !== -1;
  235. };
  236. Trigger.prototype.isBlurToHide = function isBlurToHide() {
  237. var _props7 = this.props,
  238. action = _props7.action,
  239. hideAction = _props7.hideAction;
  240. return action.indexOf('focus') !== -1 || hideAction.indexOf('blur') !== -1;
  241. };
  242. Trigger.prototype.forcePopupAlign = function forcePopupAlign() {
  243. if (this.state.popupVisible && this._component && this._component.alignInstance) {
  244. this._component.alignInstance.forceAlign();
  245. }
  246. };
  247. Trigger.prototype.fireEvents = function fireEvents(type, e) {
  248. var childCallback = this.props.children.props[type];
  249. if (childCallback) {
  250. childCallback(e);
  251. }
  252. var callback = this.props[type];
  253. if (callback) {
  254. callback(e);
  255. }
  256. };
  257. Trigger.prototype.close = function close() {
  258. this.setPopupVisible(false);
  259. };
  260. Trigger.prototype.render = function render() {
  261. var _this3 = this;
  262. var popupVisible = this.state.popupVisible;
  263. var _props8 = this.props,
  264. children = _props8.children,
  265. forceRender = _props8.forceRender,
  266. alignPoint = _props8.alignPoint,
  267. className = _props8.className;
  268. var child = React.Children.only(children);
  269. var newChildProps = { key: 'trigger' };
  270. if (this.isContextMenuToShow()) {
  271. newChildProps.onContextMenu = this.onContextMenu;
  272. } else {
  273. newChildProps.onContextMenu = this.createTwoChains('onContextMenu');
  274. }
  275. if (this.isClickToHide() || this.isClickToShow()) {
  276. newChildProps.onClick = this.onClick;
  277. newChildProps.onMouseDown = this.onMouseDown;
  278. newChildProps.onTouchStart = this.onTouchStart;
  279. } else {
  280. newChildProps.onClick = this.createTwoChains('onClick');
  281. newChildProps.onMouseDown = this.createTwoChains('onMouseDown');
  282. newChildProps.onTouchStart = this.createTwoChains('onTouchStart');
  283. }
  284. if (this.isMouseEnterToShow()) {
  285. newChildProps.onMouseEnter = this.onMouseEnter;
  286. if (alignPoint) {
  287. newChildProps.onMouseMove = this.onMouseMove;
  288. }
  289. } else {
  290. newChildProps.onMouseEnter = this.createTwoChains('onMouseEnter');
  291. }
  292. if (this.isMouseLeaveToHide()) {
  293. newChildProps.onMouseLeave = this.onMouseLeave;
  294. } else {
  295. newChildProps.onMouseLeave = this.createTwoChains('onMouseLeave');
  296. }
  297. if (this.isFocusToShow() || this.isBlurToHide()) {
  298. newChildProps.onFocus = this.onFocus;
  299. newChildProps.onBlur = this.onBlur;
  300. } else {
  301. newChildProps.onFocus = this.createTwoChains('onFocus');
  302. newChildProps.onBlur = this.createTwoChains('onBlur');
  303. }
  304. var childrenClassName = classNames(child && child.props && child.props.className, className);
  305. if (childrenClassName) {
  306. newChildProps.className = childrenClassName;
  307. }
  308. var trigger = React.cloneElement(child, newChildProps);
  309. if (!IS_REACT_16) {
  310. return React.createElement(
  311. ContainerRender,
  312. {
  313. parent: this,
  314. visible: popupVisible,
  315. autoMount: false,
  316. forceRender: forceRender,
  317. getComponent: this.getComponent,
  318. getContainer: this.getContainer
  319. },
  320. function (_ref2) {
  321. var renderComponent = _ref2.renderComponent;
  322. _this3.renderComponent = renderComponent;
  323. return trigger;
  324. }
  325. );
  326. }
  327. var portal = void 0;
  328. // prevent unmounting after it's rendered
  329. if (popupVisible || this._component || forceRender) {
  330. portal = React.createElement(
  331. Portal,
  332. { key: 'portal', getContainer: this.getContainer, didUpdate: this.handlePortalUpdate },
  333. this.getComponent()
  334. );
  335. }
  336. return [trigger, portal];
  337. };
  338. return Trigger;
  339. }(React.Component);
  340. Trigger.propTypes = {
  341. children: PropTypes.any,
  342. action: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
  343. showAction: PropTypes.any,
  344. hideAction: PropTypes.any,
  345. getPopupClassNameFromAlign: PropTypes.any,
  346. onPopupVisibleChange: PropTypes.func,
  347. afterPopupVisibleChange: PropTypes.func,
  348. popup: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
  349. popupStyle: PropTypes.object,
  350. prefixCls: PropTypes.string,
  351. popupClassName: PropTypes.string,
  352. className: PropTypes.string,
  353. popupPlacement: PropTypes.string,
  354. builtinPlacements: PropTypes.object,
  355. popupTransitionName: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
  356. popupAnimation: PropTypes.any,
  357. mouseEnterDelay: PropTypes.number,
  358. mouseLeaveDelay: PropTypes.number,
  359. zIndex: PropTypes.number,
  360. focusDelay: PropTypes.number,
  361. blurDelay: PropTypes.number,
  362. getPopupContainer: PropTypes.func,
  363. getDocument: PropTypes.func,
  364. forceRender: PropTypes.bool,
  365. destroyPopupOnHide: PropTypes.bool,
  366. mask: PropTypes.bool,
  367. maskClosable: PropTypes.bool,
  368. onPopupAlign: PropTypes.func,
  369. popupAlign: PropTypes.object,
  370. popupVisible: PropTypes.bool,
  371. defaultPopupVisible: PropTypes.bool,
  372. maskTransitionName: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
  373. maskAnimation: PropTypes.string,
  374. stretch: PropTypes.string,
  375. alignPoint: PropTypes.bool // Maybe we can support user pass position in the future
  376. };
  377. Trigger.contextTypes = contextTypes;
  378. Trigger.childContextTypes = contextTypes;
  379. Trigger.defaultProps = {
  380. prefixCls: 'rc-trigger-popup',
  381. getPopupClassNameFromAlign: returnEmptyString,
  382. getDocument: returnDocument,
  383. onPopupVisibleChange: noop,
  384. afterPopupVisibleChange: noop,
  385. onPopupAlign: noop,
  386. popupClassName: '',
  387. mouseEnterDelay: 0,
  388. mouseLeaveDelay: 0.1,
  389. focusDelay: 0,
  390. blurDelay: 0.15,
  391. popupStyle: {},
  392. destroyPopupOnHide: false,
  393. popupAlign: {},
  394. defaultPopupVisible: false,
  395. mask: false,
  396. maskClosable: true,
  397. action: [],
  398. showAction: [],
  399. hideAction: []
  400. };
  401. var _initialiseProps = function _initialiseProps() {
  402. var _this4 = this;
  403. this.onMouseEnter = function (e) {
  404. var mouseEnterDelay = _this4.props.mouseEnterDelay;
  405. _this4.fireEvents('onMouseEnter', e);
  406. _this4.delaySetPopupVisible(true, mouseEnterDelay, mouseEnterDelay ? null : e);
  407. };
  408. this.onMouseMove = function (e) {
  409. _this4.fireEvents('onMouseMove', e);
  410. _this4.setPoint(e);
  411. };
  412. this.onMouseLeave = function (e) {
  413. _this4.fireEvents('onMouseLeave', e);
  414. _this4.delaySetPopupVisible(false, _this4.props.mouseLeaveDelay);
  415. };
  416. this.onPopupMouseEnter = function () {
  417. _this4.clearDelayTimer();
  418. };
  419. this.onPopupMouseLeave = function (e) {
  420. // https://github.com/react-component/trigger/pull/13
  421. // react bug?
  422. if (e.relatedTarget && !e.relatedTarget.setTimeout && _this4._component && _this4._component.getPopupDomNode && contains(_this4._component.getPopupDomNode(), e.relatedTarget)) {
  423. return;
  424. }
  425. _this4.delaySetPopupVisible(false, _this4.props.mouseLeaveDelay);
  426. };
  427. this.onFocus = function (e) {
  428. _this4.fireEvents('onFocus', e);
  429. // incase focusin and focusout
  430. _this4.clearDelayTimer();
  431. if (_this4.isFocusToShow()) {
  432. _this4.focusTime = Date.now();
  433. _this4.delaySetPopupVisible(true, _this4.props.focusDelay);
  434. }
  435. };
  436. this.onMouseDown = function (e) {
  437. _this4.fireEvents('onMouseDown', e);
  438. _this4.preClickTime = Date.now();
  439. };
  440. this.onTouchStart = function (e) {
  441. _this4.fireEvents('onTouchStart', e);
  442. _this4.preTouchTime = Date.now();
  443. };
  444. this.onBlur = function (e) {
  445. _this4.fireEvents('onBlur', e);
  446. _this4.clearDelayTimer();
  447. if (_this4.isBlurToHide()) {
  448. _this4.delaySetPopupVisible(false, _this4.props.blurDelay);
  449. }
  450. };
  451. this.onContextMenu = function (e) {
  452. e.preventDefault();
  453. _this4.fireEvents('onContextMenu', e);
  454. _this4.setPopupVisible(true, e);
  455. };
  456. this.onContextMenuClose = function () {
  457. if (_this4.isContextMenuToShow()) {
  458. _this4.close();
  459. }
  460. };
  461. this.onClick = function (event) {
  462. _this4.fireEvents('onClick', event);
  463. // focus will trigger click
  464. if (_this4.focusTime) {
  465. var preTime = void 0;
  466. if (_this4.preClickTime && _this4.preTouchTime) {
  467. preTime = Math.min(_this4.preClickTime, _this4.preTouchTime);
  468. } else if (_this4.preClickTime) {
  469. preTime = _this4.preClickTime;
  470. } else if (_this4.preTouchTime) {
  471. preTime = _this4.preTouchTime;
  472. }
  473. if (Math.abs(preTime - _this4.focusTime) < 20) {
  474. return;
  475. }
  476. _this4.focusTime = 0;
  477. }
  478. _this4.preClickTime = 0;
  479. _this4.preTouchTime = 0;
  480. // Only prevent default when all the action is click.
  481. // https://github.com/ant-design/ant-design/issues/17043
  482. // https://github.com/ant-design/ant-design/issues/17291
  483. if (_this4.isClickToShow() && (_this4.isClickToHide() || _this4.isBlurToHide()) && event && event.preventDefault) {
  484. event.preventDefault();
  485. }
  486. var nextVisible = !_this4.state.popupVisible;
  487. if (_this4.isClickToHide() && !nextVisible || nextVisible && _this4.isClickToShow()) {
  488. _this4.setPopupVisible(!_this4.state.popupVisible, event);
  489. }
  490. };
  491. this.onPopupMouseDown = function () {
  492. var _context$rcTrigger = _this4.context.rcTrigger,
  493. rcTrigger = _context$rcTrigger === undefined ? {} : _context$rcTrigger;
  494. _this4.hasPopupMouseDown = true;
  495. clearTimeout(_this4.mouseDownTimeout);
  496. _this4.mouseDownTimeout = setTimeout(function () {
  497. _this4.hasPopupMouseDown = false;
  498. }, 0);
  499. if (rcTrigger.onPopupMouseDown) {
  500. rcTrigger.onPopupMouseDown.apply(rcTrigger, arguments);
  501. }
  502. };
  503. this.onDocumentClick = function (event) {
  504. if (_this4.props.mask && !_this4.props.maskClosable) {
  505. return;
  506. }
  507. var target = event.target;
  508. var root = findDOMNode(_this4);
  509. if (!contains(root, target) && !_this4.hasPopupMouseDown) {
  510. _this4.close();
  511. }
  512. };
  513. this.getRootDomNode = function () {
  514. return findDOMNode(_this4);
  515. };
  516. this.getPopupClassNameFromAlign = function (align) {
  517. var className = [];
  518. var _props9 = _this4.props,
  519. popupPlacement = _props9.popupPlacement,
  520. builtinPlacements = _props9.builtinPlacements,
  521. prefixCls = _props9.prefixCls,
  522. alignPoint = _props9.alignPoint,
  523. getPopupClassNameFromAlign = _props9.getPopupClassNameFromAlign;
  524. if (popupPlacement && builtinPlacements) {
  525. className.push(getAlignPopupClassName(builtinPlacements, prefixCls, align, alignPoint));
  526. }
  527. if (getPopupClassNameFromAlign) {
  528. className.push(getPopupClassNameFromAlign(align));
  529. }
  530. return className.join(' ');
  531. };
  532. this.getComponent = function () {
  533. var _props10 = _this4.props,
  534. prefixCls = _props10.prefixCls,
  535. destroyPopupOnHide = _props10.destroyPopupOnHide,
  536. popupClassName = _props10.popupClassName,
  537. action = _props10.action,
  538. onPopupAlign = _props10.onPopupAlign,
  539. popupAnimation = _props10.popupAnimation,
  540. popupTransitionName = _props10.popupTransitionName,
  541. popupStyle = _props10.popupStyle,
  542. mask = _props10.mask,
  543. maskAnimation = _props10.maskAnimation,
  544. maskTransitionName = _props10.maskTransitionName,
  545. zIndex = _props10.zIndex,
  546. popup = _props10.popup,
  547. stretch = _props10.stretch,
  548. alignPoint = _props10.alignPoint;
  549. var _state = _this4.state,
  550. popupVisible = _state.popupVisible,
  551. point = _state.point;
  552. var align = _this4.getPopupAlign();
  553. var mouseProps = {};
  554. if (_this4.isMouseEnterToShow()) {
  555. mouseProps.onMouseEnter = _this4.onPopupMouseEnter;
  556. }
  557. if (_this4.isMouseLeaveToHide()) {
  558. mouseProps.onMouseLeave = _this4.onPopupMouseLeave;
  559. }
  560. mouseProps.onMouseDown = _this4.onPopupMouseDown;
  561. mouseProps.onTouchStart = _this4.onPopupMouseDown;
  562. return React.createElement(
  563. Popup,
  564. _extends({
  565. prefixCls: prefixCls,
  566. destroyPopupOnHide: destroyPopupOnHide,
  567. visible: popupVisible,
  568. point: alignPoint && point,
  569. className: popupClassName,
  570. action: action,
  571. align: align,
  572. onAlign: onPopupAlign,
  573. animation: popupAnimation,
  574. getClassNameFromAlign: _this4.getPopupClassNameFromAlign
  575. }, mouseProps, {
  576. stretch: stretch,
  577. getRootDomNode: _this4.getRootDomNode,
  578. style: popupStyle,
  579. mask: mask,
  580. zIndex: zIndex,
  581. transitionName: popupTransitionName,
  582. maskAnimation: maskAnimation,
  583. maskTransitionName: maskTransitionName,
  584. ref: _this4.savePopup
  585. }),
  586. typeof popup === 'function' ? popup() : popup
  587. );
  588. };
  589. this.getContainer = function () {
  590. var props = _this4.props;
  591. var popupContainer = document.createElement('div');
  592. // Make sure default popup container will never cause scrollbar appearing
  593. // https://github.com/react-component/trigger/issues/41
  594. popupContainer.style.position = 'absolute';
  595. popupContainer.style.top = '0';
  596. popupContainer.style.left = '0';
  597. popupContainer.style.width = '100%';
  598. var mountNode = props.getPopupContainer ? props.getPopupContainer(findDOMNode(_this4)) : props.getDocument().body;
  599. mountNode.appendChild(popupContainer);
  600. return popupContainer;
  601. };
  602. this.setPoint = function (point) {
  603. var alignPoint = _this4.props.alignPoint;
  604. if (!alignPoint || !point) return;
  605. _this4.setState({
  606. point: {
  607. pageX: point.pageX,
  608. pageY: point.pageY
  609. }
  610. });
  611. };
  612. this.handlePortalUpdate = function () {
  613. if (_this4.state.prevPopupVisible !== _this4.state.popupVisible) {
  614. _this4.props.afterPopupVisibleChange(_this4.state.popupVisible);
  615. }
  616. };
  617. this.savePopup = function (node) {
  618. _this4._component = node;
  619. };
  620. };
  621. polyfill(Trigger);
  622. export default Trigger;