@rc-component/select 1.2.2 → 1.2.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 +0 -3
- package/es/SelectInput/index.js +7 -1
- package/es/hooks/useOpen.d.ts +1 -0
- package/es/hooks/useOpen.js +3 -4
- package/lib/BaseSelect/index.js +0 -3
- package/lib/SelectInput/index.js +7 -1
- package/lib/hooks/useOpen.d.ts +1 -0
- package/lib/hooks/useOpen.js +4 -4
- package/package.json +1 -1
package/es/BaseSelect/index.js
CHANGED
package/es/SelectInput/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { isValidateOpenKey } from "../utils/keyUtil";
|
|
|
10
10
|
import { clsx } from 'clsx';
|
|
11
11
|
import { getDOM } from "@rc-component/util/es/Dom/findDOMNode";
|
|
12
12
|
import { composeRef } from "@rc-component/util/es/ref";
|
|
13
|
+
import { macroTask } from "../hooks/useOpen";
|
|
13
14
|
const DEFAULT_OMIT_PROPS = ['value', 'onChange', 'removeIcon', 'placeholder', 'maxTagCount', 'maxTagTextLength', 'maxTagPlaceholder', 'choiceTransitionName', 'onInputKeyDown', 'onPopupScroll', 'tabIndex', 'activeValue', 'onSelectorRemove', 'focused'];
|
|
14
15
|
export default /*#__PURE__*/React.forwardRef(function SelectInput(props, ref) {
|
|
15
16
|
const {
|
|
@@ -129,7 +130,12 @@ export default /*#__PURE__*/React.forwardRef(function SelectInput(props, ref) {
|
|
|
129
130
|
onMouseDown?.(event);
|
|
130
131
|
});
|
|
131
132
|
const onInternalBlur = event => {
|
|
132
|
-
|
|
133
|
+
macroTask(() => {
|
|
134
|
+
const inputNode = getDOM(inputRef.current);
|
|
135
|
+
if (!inputNode || inputNode !== document.activeElement && !inputNode.contains(document.activeElement)) {
|
|
136
|
+
toggleOpen(false);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
133
139
|
onBlur?.(event);
|
|
134
140
|
};
|
|
135
141
|
|
package/es/hooks/useOpen.d.ts
CHANGED
package/es/hooks/useOpen.js
CHANGED
|
@@ -5,7 +5,7 @@ const internalMacroTask = fn => {
|
|
|
5
5
|
channel.port1.onmessage = fn;
|
|
6
6
|
channel.port2.postMessage(null);
|
|
7
7
|
};
|
|
8
|
-
const macroTask = (fn, times = 1) => {
|
|
8
|
+
export const macroTask = (fn, times = 1) => {
|
|
9
9
|
if (times <= 0) {
|
|
10
10
|
fn();
|
|
11
11
|
return;
|
|
@@ -50,15 +50,14 @@ export default function useOpen(propOpen, onOpen, postOpen) {
|
|
|
50
50
|
});
|
|
51
51
|
const toggleOpen = useEvent((nextOpen, config = {}) => {
|
|
52
52
|
const {
|
|
53
|
-
ignoreNext = false
|
|
54
|
-
lazy = false
|
|
53
|
+
ignoreNext = false
|
|
55
54
|
} = config;
|
|
56
55
|
taskIdRef.current += 1;
|
|
57
56
|
const id = taskIdRef.current;
|
|
58
57
|
const nextOpenVal = typeof nextOpen === 'boolean' ? nextOpen : !mergedOpen;
|
|
59
58
|
|
|
60
59
|
// Since `mergedOpen` is post-processed, we need to check if the value really changed
|
|
61
|
-
if (nextOpenVal
|
|
60
|
+
if (nextOpenVal) {
|
|
62
61
|
if (!taskLockRef.current) {
|
|
63
62
|
triggerEvent(nextOpenVal);
|
|
64
63
|
|
package/lib/BaseSelect/index.js
CHANGED
package/lib/SelectInput/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var _keyUtil = require("../utils/keyUtil");
|
|
|
15
15
|
var _clsx = require("clsx");
|
|
16
16
|
var _findDOMNode = require("@rc-component/util/lib/Dom/findDOMNode");
|
|
17
17
|
var _ref = require("@rc-component/util/lib/ref");
|
|
18
|
+
var _useOpen = require("../hooks/useOpen");
|
|
18
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
20
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
20
21
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -138,7 +139,12 @@ var _default = exports.default = /*#__PURE__*/React.forwardRef(function SelectIn
|
|
|
138
139
|
onMouseDown?.(event);
|
|
139
140
|
});
|
|
140
141
|
const onInternalBlur = event => {
|
|
141
|
-
|
|
142
|
+
(0, _useOpen.macroTask)(() => {
|
|
143
|
+
const inputNode = (0, _findDOMNode.getDOM)(inputRef.current);
|
|
144
|
+
if (!inputNode || inputNode !== document.activeElement && !inputNode.contains(document.activeElement)) {
|
|
145
|
+
toggleOpen(false);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
142
148
|
onBlur?.(event);
|
|
143
149
|
};
|
|
144
150
|
|
package/lib/hooks/useOpen.d.ts
CHANGED
package/lib/hooks/useOpen.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = useOpen;
|
|
7
|
+
exports.macroTask = void 0;
|
|
7
8
|
var _util = require("@rc-component/util");
|
|
8
9
|
var _react = require("react");
|
|
9
10
|
const internalMacroTask = fn => {
|
|
@@ -25,7 +26,7 @@ const macroTask = (fn, times = 1) => {
|
|
|
25
26
|
* Trigger by latest open call, if nextOpen is undefined, means toggle.
|
|
26
27
|
* ignoreNext will skip next call in the macro task queue.
|
|
27
28
|
*/
|
|
28
|
-
|
|
29
|
+
exports.macroTask = macroTask;
|
|
29
30
|
/**
|
|
30
31
|
* When `open` is controlled, follow the controlled value;
|
|
31
32
|
* Otherwise use uncontrolled logic.
|
|
@@ -56,15 +57,14 @@ function useOpen(propOpen, onOpen, postOpen) {
|
|
|
56
57
|
});
|
|
57
58
|
const toggleOpen = (0, _util.useEvent)((nextOpen, config = {}) => {
|
|
58
59
|
const {
|
|
59
|
-
ignoreNext = false
|
|
60
|
-
lazy = false
|
|
60
|
+
ignoreNext = false
|
|
61
61
|
} = config;
|
|
62
62
|
taskIdRef.current += 1;
|
|
63
63
|
const id = taskIdRef.current;
|
|
64
64
|
const nextOpenVal = typeof nextOpen === 'boolean' ? nextOpen : !mergedOpen;
|
|
65
65
|
|
|
66
66
|
// Since `mergedOpen` is post-processed, we need to check if the value really changed
|
|
67
|
-
if (nextOpenVal
|
|
67
|
+
if (nextOpenVal) {
|
|
68
68
|
if (!taskLockRef.current) {
|
|
69
69
|
triggerEvent(nextOpenVal);
|
|
70
70
|
|