@rc-component/select 1.2.2 → 1.2.4
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/Select.d.ts +1 -1
- package/es/SelectInput/index.js +12 -1
- package/es/hooks/useOpen.d.ts +1 -0
- package/es/hooks/useOpen.js +3 -4
- package/es/hooks/useSelectTriggerControl.js +3 -1
- package/lib/BaseSelect/index.js +0 -3
- package/lib/Select.d.ts +1 -1
- package/lib/SelectInput/index.js +12 -1
- package/lib/hooks/useOpen.d.ts +1 -0
- package/lib/hooks/useOpen.js +4 -4
- package/lib/hooks/useSelectTriggerControl.js +3 -1
- package/package.json +1 -1
package/es/BaseSelect/index.js
CHANGED
package/es/Select.d.ts
CHANGED
|
@@ -125,7 +125,7 @@ export interface SelectProps<ValueType = any, OptionType extends BaseOptionType
|
|
|
125
125
|
classNames?: Partial<Record<SemanticName, string>>;
|
|
126
126
|
styles?: Partial<Record<SemanticName, React.CSSProperties>>;
|
|
127
127
|
}
|
|
128
|
-
declare const TypedSelect: (<ValueType = any, OptionType extends
|
|
128
|
+
declare const TypedSelect: (<ValueType = any, OptionType extends DefaultOptionType | BaseOptionType = DefaultOptionType>(props: React.PropsWithChildren<SelectProps<ValueType, OptionType>> & React.RefAttributes<BaseSelectRef>) => React.ReactElement) & {
|
|
129
129
|
Option: typeof Option;
|
|
130
130
|
OptGroup: typeof OptGroup;
|
|
131
131
|
};
|
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 {
|
|
@@ -106,6 +107,11 @@ export default /*#__PURE__*/React.forwardRef(function SelectInput(props, ref) {
|
|
|
106
107
|
// ====================== Open ======================
|
|
107
108
|
const onInternalMouseDown = useEvent(event => {
|
|
108
109
|
if (!disabled) {
|
|
110
|
+
// https://github.com/ant-design/ant-design/issues/56002
|
|
111
|
+
// Tell `useSelectTriggerControl` to ignore this event
|
|
112
|
+
// When icon is dynamic render, the parentNode will miss
|
|
113
|
+
// so we need to mark the event directly
|
|
114
|
+
event.nativeEvent._ignore_global_close = true;
|
|
109
115
|
const inputDOM = getDOM(inputRef.current);
|
|
110
116
|
if (inputDOM && event.target !== inputDOM && !inputDOM.contains(event.target)) {
|
|
111
117
|
event.preventDefault();
|
|
@@ -129,7 +135,12 @@ export default /*#__PURE__*/React.forwardRef(function SelectInput(props, ref) {
|
|
|
129
135
|
onMouseDown?.(event);
|
|
130
136
|
});
|
|
131
137
|
const onInternalBlur = event => {
|
|
132
|
-
|
|
138
|
+
macroTask(() => {
|
|
139
|
+
const inputNode = getDOM(inputRef.current);
|
|
140
|
+
if (!inputNode || inputNode !== document.activeElement && !inputNode.contains(document.activeElement)) {
|
|
141
|
+
toggleOpen(false);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
133
144
|
onBlur?.(event);
|
|
134
145
|
};
|
|
135
146
|
|
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
|
|
|
@@ -10,7 +10,9 @@ export default function useSelectTriggerControl(elements, open, triggerOpen, cus
|
|
|
10
10
|
if (target.shadowRoot && event.composed) {
|
|
11
11
|
target = event.composedPath()[0] || target;
|
|
12
12
|
}
|
|
13
|
-
if (open &&
|
|
13
|
+
if (open &&
|
|
14
|
+
// Marked by SelectInput mouseDown event
|
|
15
|
+
!event._ignore_global_close && elements().filter(element => element).every(element => !element.contains(target) && element !== target)) {
|
|
14
16
|
// Should trigger close
|
|
15
17
|
triggerOpen(false);
|
|
16
18
|
}
|
package/lib/BaseSelect/index.js
CHANGED
package/lib/Select.d.ts
CHANGED
|
@@ -125,7 +125,7 @@ export interface SelectProps<ValueType = any, OptionType extends BaseOptionType
|
|
|
125
125
|
classNames?: Partial<Record<SemanticName, string>>;
|
|
126
126
|
styles?: Partial<Record<SemanticName, React.CSSProperties>>;
|
|
127
127
|
}
|
|
128
|
-
declare const TypedSelect: (<ValueType = any, OptionType extends
|
|
128
|
+
declare const TypedSelect: (<ValueType = any, OptionType extends DefaultOptionType | BaseOptionType = DefaultOptionType>(props: React.PropsWithChildren<SelectProps<ValueType, OptionType>> & React.RefAttributes<BaseSelectRef>) => React.ReactElement) & {
|
|
129
129
|
Option: typeof Option;
|
|
130
130
|
OptGroup: typeof OptGroup;
|
|
131
131
|
};
|
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; }
|
|
@@ -115,6 +116,11 @@ var _default = exports.default = /*#__PURE__*/React.forwardRef(function SelectIn
|
|
|
115
116
|
// ====================== Open ======================
|
|
116
117
|
const onInternalMouseDown = (0, _util.useEvent)(event => {
|
|
117
118
|
if (!disabled) {
|
|
119
|
+
// https://github.com/ant-design/ant-design/issues/56002
|
|
120
|
+
// Tell `useSelectTriggerControl` to ignore this event
|
|
121
|
+
// When icon is dynamic render, the parentNode will miss
|
|
122
|
+
// so we need to mark the event directly
|
|
123
|
+
event.nativeEvent._ignore_global_close = true;
|
|
118
124
|
const inputDOM = (0, _findDOMNode.getDOM)(inputRef.current);
|
|
119
125
|
if (inputDOM && event.target !== inputDOM && !inputDOM.contains(event.target)) {
|
|
120
126
|
event.preventDefault();
|
|
@@ -138,7 +144,12 @@ var _default = exports.default = /*#__PURE__*/React.forwardRef(function SelectIn
|
|
|
138
144
|
onMouseDown?.(event);
|
|
139
145
|
});
|
|
140
146
|
const onInternalBlur = event => {
|
|
141
|
-
|
|
147
|
+
(0, _useOpen.macroTask)(() => {
|
|
148
|
+
const inputNode = (0, _findDOMNode.getDOM)(inputRef.current);
|
|
149
|
+
if (!inputNode || inputNode !== document.activeElement && !inputNode.contains(document.activeElement)) {
|
|
150
|
+
toggleOpen(false);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
142
153
|
onBlur?.(event);
|
|
143
154
|
};
|
|
144
155
|
|
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
|
|
|
@@ -18,7 +18,9 @@ function useSelectTriggerControl(elements, open, triggerOpen, customizedTrigger)
|
|
|
18
18
|
if (target.shadowRoot && event.composed) {
|
|
19
19
|
target = event.composedPath()[0] || target;
|
|
20
20
|
}
|
|
21
|
-
if (open &&
|
|
21
|
+
if (open &&
|
|
22
|
+
// Marked by SelectInput mouseDown event
|
|
23
|
+
!event._ignore_global_close && elements().filter(element => element).every(element => !element.contains(target) && element !== target)) {
|
|
22
24
|
// Should trigger close
|
|
23
25
|
triggerOpen(false);
|
|
24
26
|
}
|