@rc-component/select 1.2.0-alpha.2 → 1.2.0-alpha.3
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/es/BaseSelect/index.js +6 -2
- package/es/hooks/useOpen.d.ts +4 -1
- package/es/hooks/useOpen.js +16 -10
- package/lib/BaseSelect/index.js +6 -2
- package/lib/hooks/useOpen.d.ts +4 -1
- package/lib/hooks/useOpen.js +16 -10
- package/package.json +1 -1
package/es/BaseSelect/index.js
CHANGED
|
@@ -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,
|
|
336
|
+
triggerOpen(true, {
|
|
337
|
+
ignoreNext: true
|
|
338
|
+
});
|
|
335
339
|
}
|
|
336
340
|
onMouseDown?.(event, ...restArgs);
|
|
337
341
|
};
|
package/es/hooks/useOpen.d.ts
CHANGED
|
@@ -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,
|
|
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.
|
package/es/hooks/useOpen.js
CHANGED
|
@@ -48,27 +48,33 @@ export default function useOpen(propOpen, onOpen, postOpen) {
|
|
|
48
48
|
}
|
|
49
49
|
internalSetOpen(nextOpen);
|
|
50
50
|
});
|
|
51
|
-
const toggleOpen = useEvent((nextOpen,
|
|
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
|
-
|
|
61
|
+
if (nextOpenVal || !lazy) {
|
|
62
|
+
if (!taskLockRef.current) {
|
|
63
|
+
triggerEvent(nextOpenVal);
|
|
59
64
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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(
|
|
77
|
+
triggerEvent(nextOpenVal);
|
|
72
78
|
}
|
|
73
79
|
});
|
|
74
80
|
});
|
package/lib/BaseSelect/index.js
CHANGED
|
@@ -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,
|
|
345
|
+
triggerOpen(true, {
|
|
346
|
+
ignoreNext: true
|
|
347
|
+
});
|
|
344
348
|
}
|
|
345
349
|
onMouseDown?.(event, ...restArgs);
|
|
346
350
|
};
|
package/lib/hooks/useOpen.d.ts
CHANGED
|
@@ -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,
|
|
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.
|
package/lib/hooks/useOpen.js
CHANGED
|
@@ -54,27 +54,33 @@ function useOpen(propOpen, onOpen, postOpen) {
|
|
|
54
54
|
}
|
|
55
55
|
internalSetOpen(nextOpen);
|
|
56
56
|
});
|
|
57
|
-
const toggleOpen = (0, _util.useEvent)((nextOpen,
|
|
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
|
-
|
|
67
|
+
if (nextOpenVal || !lazy) {
|
|
68
|
+
if (!taskLockRef.current) {
|
|
69
|
+
triggerEvent(nextOpenVal);
|
|
65
70
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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(
|
|
83
|
+
triggerEvent(nextOpenVal);
|
|
78
84
|
}
|
|
79
85
|
});
|
|
80
86
|
});
|