@rc-component/trigger 1.10.0 → 1.10.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.
package/README.md CHANGED
@@ -65,8 +65,6 @@ ReactDOM.render((
65
65
 
66
66
  http://localhost:9001
67
67
 
68
- online example: http://react-component.github.io/trigger/
69
-
70
68
  ## Development
71
69
 
72
70
  ```
@@ -252,75 +250,11 @@ npm start
252
250
 
253
251
  ```
254
252
  npm test
255
- npm run chrome-test
256
- ```
257
-
258
- ## Coverage
259
-
260
- ```
261
253
  npm run coverage
262
254
  ```
263
255
 
264
256
  open coverage/ dir
265
257
 
266
- ## React 16 Note
267
-
268
- After React 16, you won't access popup element's ref in parent component's componentDidMount, which means following code won't work.
269
-
270
- ```javascript
271
- class App extends React.Component {
272
- componentDidMount() {
273
- this.input.focus(); // error, this.input is undefined.
274
- }
275
-
276
- render() {
277
- return (
278
- <Trigger
279
- action={['click']}
280
- popup={<div><input ref={node => this.input = node} type="text" /></div>}
281
- >
282
- <button>click</button>
283
- </Trigger>
284
- )
285
- }
286
- }
287
- ```
288
-
289
- Consider wrap your popup element to a separate component:
290
-
291
- ```javascript
292
- class InputPopup extends React.Component {
293
- componentDidMount() {
294
- this.props.onMount();
295
- }
296
-
297
- render() {
298
- return (
299
- <div>
300
- <input ref={this.props.inputRef} type="text" />
301
- </div>
302
- );
303
- }
304
- }
305
-
306
- class App extends React.Component {
307
- handlePopupMount() {
308
- this.input.focus(); // error, this.input is undefined.
309
- }
310
-
311
- render() {
312
- return (
313
- <Trigger
314
- action={['click']}
315
- popup={<InputPopup inputRef={node => this.input = node} onMount={this.handlePopupMount} />}
316
- >
317
- <button>click</button>
318
- </Trigger>
319
- )
320
- }
321
- }
322
- ```
323
-
324
258
  ## License
325
259
 
326
260
  rc-trigger is released under the MIT license.
package/es/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { CSSMotionProps } from 'rc-motion';
2
2
  import * as React from 'react';
3
- import type { ActionType, AlignType, ArrowTypeOuter, AnimationType, BuildInPlacements, TransitionNameType } from './interface';
4
- export type { BuildInPlacements, AlignType, ActionType, ArrowTypeOuter as ArrowType };
3
+ import type { ActionType, AlignType, AnimationType, ArrowTypeOuter, BuildInPlacements, TransitionNameType } from './interface';
4
+ export type { BuildInPlacements, AlignType, ActionType, ArrowTypeOuter as ArrowType, };
5
5
  export interface TriggerRef {
6
6
  forceAlign: VoidFunction;
7
7
  }
package/es/index.js CHANGED
@@ -327,19 +327,29 @@ export function generateTrigger() {
327
327
  // Click to hide is special action since click popup element should not hide
328
328
  React.useEffect(function () {
329
329
  if (clickToHide && popupEle && (!mask || maskClosable)) {
330
- var onWindowClick = function onWindowClick(_ref) {
330
+ var clickInside = false;
331
+
332
+ // User may mouseDown inside and drag out of popup and mouse up
333
+ // Record here to prevent close
334
+ var onWindowMouseDown = function onWindowMouseDown(_ref) {
331
335
  var target = _ref.target;
332
- if (openRef.current && !inPopupOrChild(target)) {
336
+ clickInside = inPopupOrChild(target);
337
+ };
338
+ var onWindowClick = function onWindowClick(_ref2) {
339
+ var target = _ref2.target;
340
+ if (openRef.current && !clickInside && !inPopupOrChild(target)) {
333
341
  triggerOpen(false);
334
342
  }
335
343
  };
336
344
  var win = getWin(popupEle);
337
345
  var targetRoot = targetEle === null || targetEle === void 0 ? void 0 : targetEle.getRootNode();
346
+ win.addEventListener('mousedown', onWindowMouseDown);
338
347
  win.addEventListener('click', onWindowClick);
339
348
 
340
349
  // shadow root
341
350
  var inShadow = targetRoot && targetRoot !== targetEle.ownerDocument;
342
351
  if (inShadow) {
352
+ targetRoot.addEventListener('mousedown', onWindowMouseDown);
343
353
  targetRoot.addEventListener('click', onWindowClick);
344
354
  }
345
355
 
@@ -349,8 +359,10 @@ export function generateTrigger() {
349
359
  warning(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
350
360
  }
351
361
  return function () {
362
+ win.removeEventListener('mousedown', onWindowMouseDown);
352
363
  win.removeEventListener('click', onWindowClick);
353
364
  if (inShadow) {
365
+ targetRoot.removeEventListener('mousedown', onWindowMouseDown);
354
366
  targetRoot.removeEventListener('click', onWindowClick);
355
367
  }
356
368
  };
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { CSSMotionProps } from 'rc-motion';
2
2
  import * as React from 'react';
3
- import type { ActionType, AlignType, ArrowTypeOuter, AnimationType, BuildInPlacements, TransitionNameType } from './interface';
4
- export type { BuildInPlacements, AlignType, ActionType, ArrowTypeOuter as ArrowType };
3
+ import type { ActionType, AlignType, AnimationType, ArrowTypeOuter, BuildInPlacements, TransitionNameType } from './interface';
4
+ export type { BuildInPlacements, AlignType, ActionType, ArrowTypeOuter as ArrowType, };
5
5
  export interface TriggerRef {
6
6
  forceAlign: VoidFunction;
7
7
  }
package/lib/index.js CHANGED
@@ -336,19 +336,29 @@ function generateTrigger() {
336
336
  // Click to hide is special action since click popup element should not hide
337
337
  React.useEffect(function () {
338
338
  if (clickToHide && popupEle && (!mask || maskClosable)) {
339
- var onWindowClick = function onWindowClick(_ref) {
339
+ var clickInside = false;
340
+
341
+ // User may mouseDown inside and drag out of popup and mouse up
342
+ // Record here to prevent close
343
+ var onWindowMouseDown = function onWindowMouseDown(_ref) {
340
344
  var target = _ref.target;
341
- if (openRef.current && !inPopupOrChild(target)) {
345
+ clickInside = inPopupOrChild(target);
346
+ };
347
+ var onWindowClick = function onWindowClick(_ref2) {
348
+ var target = _ref2.target;
349
+ if (openRef.current && !clickInside && !inPopupOrChild(target)) {
342
350
  triggerOpen(false);
343
351
  }
344
352
  };
345
353
  var win = (0, _util.getWin)(popupEle);
346
354
  var targetRoot = targetEle === null || targetEle === void 0 ? void 0 : targetEle.getRootNode();
355
+ win.addEventListener('mousedown', onWindowMouseDown);
347
356
  win.addEventListener('click', onWindowClick);
348
357
 
349
358
  // shadow root
350
359
  var inShadow = targetRoot && targetRoot !== targetEle.ownerDocument;
351
360
  if (inShadow) {
361
+ targetRoot.addEventListener('mousedown', onWindowMouseDown);
352
362
  targetRoot.addEventListener('click', onWindowClick);
353
363
  }
354
364
 
@@ -358,8 +368,10 @@ function generateTrigger() {
358
368
  (0, _warning.default)(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
359
369
  }
360
370
  return function () {
371
+ win.removeEventListener('mousedown', onWindowMouseDown);
361
372
  win.removeEventListener('click', onWindowClick);
362
373
  if (inShadow) {
374
+ targetRoot.removeEventListener('mousedown', onWindowMouseDown);
363
375
  targetRoot.removeEventListener('click', onWindowClick);
364
376
  }
365
377
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/trigger",
3
- "version": "1.10.0",
3
+ "version": "1.10.2",
4
4
  "description": "base abstract trigger component for react",
5
5
  "engines": {
6
6
  "node": ">=8.x"