@rc-component/select 1.2.0-alpha.2 → 1.2.0

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.
@@ -318,7 +318,9 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
318
318
  }
319
319
  }
320
320
  if (!disabled) {
321
- triggerOpen(false);
321
+ triggerOpen(false, {
322
+ lazy: true
323
+ });
322
324
  onBlur?.(event);
323
325
  }
324
326
  };
@@ -331,7 +333,9 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
331
333
  // We should give focus back to selector if clicked item is not focusable
332
334
  if (popupElement?.contains(target) && triggerOpen) {
333
335
  // Tell `open` not to close since it's safe in the popup
334
- triggerOpen(true, true);
336
+ triggerOpen(true, {
337
+ ignoreNext: true
338
+ });
335
339
  }
336
340
  onMouseDown?.(event, ...restArgs);
337
341
  };
@@ -2,7 +2,10 @@
2
2
  * Trigger by latest open call, if nextOpen is undefined, means toggle.
3
3
  * ignoreNext will skip next call in the macro task queue.
4
4
  */
5
- export type TriggerOpenType = (nextOpen?: boolean, ignoreNext?: boolean) => void;
5
+ export type TriggerOpenType = (nextOpen?: boolean, config?: {
6
+ ignoreNext?: boolean;
7
+ lazy?: boolean;
8
+ }) => void;
6
9
  /**
7
10
  * When `open` is controlled, follow the controlled value;
8
11
  * Otherwise use uncontrolled logic.
@@ -48,27 +48,33 @@ export default function useOpen(propOpen, onOpen, postOpen) {
48
48
  }
49
49
  internalSetOpen(nextOpen);
50
50
  });
51
- const toggleOpen = useEvent((nextOpen, ignoreNext = false) => {
51
+ const toggleOpen = useEvent((nextOpen, config = {}) => {
52
+ const {
53
+ ignoreNext = false,
54
+ lazy = false
55
+ } = config;
52
56
  taskIdRef.current += 1;
53
57
  const id = taskIdRef.current;
54
58
  const nextOpenVal = typeof nextOpen === 'boolean' ? nextOpen : !mergedOpen;
55
59
 
56
60
  // Since `mergedOpen` is post-processed, we need to check if the value really changed
57
- if (nextOpenVal) {
58
- triggerEvent(true);
61
+ if (nextOpenVal || !lazy) {
62
+ if (!taskLockRef.current) {
63
+ triggerEvent(nextOpenVal);
59
64
 
60
- // Lock if needed
61
- if (ignoreNext) {
62
- taskLockRef.current = ignoreNext;
63
- macroTask(() => {
64
- taskLockRef.current = false;
65
- }, 2);
65
+ // Lock if needed
66
+ if (ignoreNext) {
67
+ taskLockRef.current = ignoreNext;
68
+ macroTask(() => {
69
+ taskLockRef.current = false;
70
+ }, 2);
71
+ }
66
72
  }
67
73
  return;
68
74
  }
69
75
  macroTask(() => {
70
76
  if (id === taskIdRef.current && !taskLockRef.current) {
71
- triggerEvent(false);
77
+ triggerEvent(nextOpenVal);
72
78
  }
73
79
  });
74
80
  });
@@ -327,7 +327,9 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
327
327
  }
328
328
  }
329
329
  if (!disabled) {
330
- triggerOpen(false);
330
+ triggerOpen(false, {
331
+ lazy: true
332
+ });
331
333
  onBlur?.(event);
332
334
  }
333
335
  };
@@ -340,7 +342,9 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
340
342
  // We should give focus back to selector if clicked item is not focusable
341
343
  if (popupElement?.contains(target) && triggerOpen) {
342
344
  // Tell `open` not to close since it's safe in the popup
343
- triggerOpen(true, true);
345
+ triggerOpen(true, {
346
+ ignoreNext: true
347
+ });
344
348
  }
345
349
  onMouseDown?.(event, ...restArgs);
346
350
  };
@@ -2,7 +2,10 @@
2
2
  * Trigger by latest open call, if nextOpen is undefined, means toggle.
3
3
  * ignoreNext will skip next call in the macro task queue.
4
4
  */
5
- export type TriggerOpenType = (nextOpen?: boolean, ignoreNext?: boolean) => void;
5
+ export type TriggerOpenType = (nextOpen?: boolean, config?: {
6
+ ignoreNext?: boolean;
7
+ lazy?: boolean;
8
+ }) => void;
6
9
  /**
7
10
  * When `open` is controlled, follow the controlled value;
8
11
  * Otherwise use uncontrolled logic.
@@ -54,27 +54,33 @@ function useOpen(propOpen, onOpen, postOpen) {
54
54
  }
55
55
  internalSetOpen(nextOpen);
56
56
  });
57
- const toggleOpen = (0, _util.useEvent)((nextOpen, ignoreNext = false) => {
57
+ const toggleOpen = (0, _util.useEvent)((nextOpen, config = {}) => {
58
+ const {
59
+ ignoreNext = false,
60
+ lazy = false
61
+ } = config;
58
62
  taskIdRef.current += 1;
59
63
  const id = taskIdRef.current;
60
64
  const nextOpenVal = typeof nextOpen === 'boolean' ? nextOpen : !mergedOpen;
61
65
 
62
66
  // Since `mergedOpen` is post-processed, we need to check if the value really changed
63
- if (nextOpenVal) {
64
- triggerEvent(true);
67
+ if (nextOpenVal || !lazy) {
68
+ if (!taskLockRef.current) {
69
+ triggerEvent(nextOpenVal);
65
70
 
66
- // Lock if needed
67
- if (ignoreNext) {
68
- taskLockRef.current = ignoreNext;
69
- macroTask(() => {
70
- taskLockRef.current = false;
71
- }, 2);
71
+ // Lock if needed
72
+ if (ignoreNext) {
73
+ taskLockRef.current = ignoreNext;
74
+ macroTask(() => {
75
+ taskLockRef.current = false;
76
+ }, 2);
77
+ }
72
78
  }
73
79
  return;
74
80
  }
75
81
  macroTask(() => {
76
82
  if (id === taskIdRef.current && !taskLockRef.current) {
77
- triggerEvent(false);
83
+ triggerEvent(nextOpenVal);
78
84
  }
79
85
  });
80
86
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/select",
3
- "version": "1.2.0-alpha.2",
3
+ "version": "1.2.0",
4
4
  "description": "React Select",
5
5
  "engines": {
6
6
  "node": ">=8.x"