@rc-component/select 1.1.3 → 1.1.5
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 +2 -5
- package/es/Select.d.ts +1 -1
- package/es/Select.js +4 -8
- package/es/hooks/useDelayReset.js +16 -7
- package/lib/BaseSelect/index.js +2 -5
- package/lib/Select.d.ts +1 -1
- package/lib/Select.js +4 -8
- package/lib/hooks/useDelayReset.js +16 -7
- package/package.json +2 -2
package/es/BaseSelect/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
import cls from 'classnames';
|
|
3
3
|
import useLayoutEffect from "@rc-component/util/es/hooks/useLayoutEffect";
|
|
4
|
-
import
|
|
4
|
+
import useControlledState from "@rc-component/util/es/hooks/useControlledState";
|
|
5
5
|
import isMobile from "@rc-component/util/es/isMobile";
|
|
6
6
|
import { useComposeRef } from "@rc-component/util/es/ref";
|
|
7
7
|
import { getDOM } from "@rc-component/util/es/Dom/findDOMNode";
|
|
@@ -150,10 +150,7 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
150
150
|
useLayoutEffect(() => {
|
|
151
151
|
setRendered(true);
|
|
152
152
|
}, []);
|
|
153
|
-
const [innerOpen, setInnerOpen] =
|
|
154
|
-
defaultValue: defaultOpen,
|
|
155
|
-
value: open
|
|
156
|
-
});
|
|
153
|
+
const [innerOpen, setInnerOpen] = useControlledState(defaultOpen || false, open);
|
|
157
154
|
let mergedOpen = rendered ? innerOpen : false;
|
|
158
155
|
|
|
159
156
|
// Not trigger `open` in `combobox` when `notFoundContent` is empty
|
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 BaseOptionType | DefaultOptionType = 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/Select.js
CHANGED
|
@@ -30,7 +30,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
30
30
|
* - `combobox` mode not support `optionLabelProp`
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
import
|
|
33
|
+
import useControlledState from "@rc-component/util/es/hooks/useControlledState";
|
|
34
34
|
import warning from "@rc-component/util/es/warning";
|
|
35
35
|
import * as React from 'react';
|
|
36
36
|
import BaseSelect, { isMultiple } from "./BaseSelect";
|
|
@@ -127,10 +127,8 @@ const Select = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
127
127
|
/* eslint-enable react-hooks/exhaustive-deps */);
|
|
128
128
|
|
|
129
129
|
// =========================== Search ===========================
|
|
130
|
-
const [
|
|
131
|
-
|
|
132
|
-
postState: search => search || ''
|
|
133
|
-
});
|
|
130
|
+
const [internalSearchValue, setSearchValue] = useControlledState('', searchValue);
|
|
131
|
+
const mergedSearchValue = internalSearchValue || '';
|
|
134
132
|
|
|
135
133
|
// =========================== Option ===========================
|
|
136
134
|
const parsedOptions = useOptions(options, children, mergedFieldNames, optionFilterProp, optionLabelProp);
|
|
@@ -185,9 +183,7 @@ const Select = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
185
183
|
}, [mergedFieldNames, optionLabelProp, valueOptions]);
|
|
186
184
|
|
|
187
185
|
// =========================== Values ===========================
|
|
188
|
-
const [internalValue, setInternalValue] =
|
|
189
|
-
value
|
|
190
|
-
});
|
|
186
|
+
const [internalValue, setInternalValue] = useControlledState(defaultValue, value);
|
|
191
187
|
|
|
192
188
|
// Merged value with LabelValueType
|
|
193
189
|
const rawLabeledValues = React.useMemo(() => {
|
|
@@ -10,15 +10,24 @@ export default function useDelayReset(timeout = 10) {
|
|
|
10
10
|
const cancelLatest = () => {
|
|
11
11
|
window.clearTimeout(delayRef.current);
|
|
12
12
|
};
|
|
13
|
-
React.useEffect(() =>
|
|
13
|
+
React.useEffect(() => {
|
|
14
|
+
return () => {
|
|
15
|
+
cancelLatest();
|
|
16
|
+
};
|
|
17
|
+
}, []);
|
|
14
18
|
const delaySetBool = (value, callback) => {
|
|
15
19
|
cancelLatest();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
if (value === true) {
|
|
21
|
+
// true 值立即设置
|
|
22
|
+
setBool(true);
|
|
23
|
+
callback?.();
|
|
24
|
+
} else {
|
|
25
|
+
// false 值延迟设置
|
|
26
|
+
delayRef.current = window.setTimeout(() => {
|
|
27
|
+
setBool(false);
|
|
28
|
+
callback?.();
|
|
29
|
+
}, timeout);
|
|
30
|
+
}
|
|
22
31
|
};
|
|
23
32
|
return [bool, delaySetBool, cancelLatest];
|
|
24
33
|
}
|
package/lib/BaseSelect/index.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.isMultiple = exports.default = void 0;
|
|
7
7
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
8
8
|
var _useLayoutEffect = _interopRequireDefault(require("@rc-component/util/lib/hooks/useLayoutEffect"));
|
|
9
|
-
var
|
|
9
|
+
var _useControlledState = _interopRequireDefault(require("@rc-component/util/lib/hooks/useControlledState"));
|
|
10
10
|
var _isMobile = _interopRequireDefault(require("@rc-component/util/lib/isMobile"));
|
|
11
11
|
var _ref = require("@rc-component/util/lib/ref");
|
|
12
12
|
var _findDOMNode = require("@rc-component/util/lib/Dom/findDOMNode");
|
|
@@ -160,10 +160,7 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
160
160
|
(0, _useLayoutEffect.default)(() => {
|
|
161
161
|
setRendered(true);
|
|
162
162
|
}, []);
|
|
163
|
-
const [innerOpen, setInnerOpen] = (0,
|
|
164
|
-
defaultValue: defaultOpen,
|
|
165
|
-
value: open
|
|
166
|
-
});
|
|
163
|
+
const [innerOpen, setInnerOpen] = (0, _useControlledState.default)(defaultOpen || false, open);
|
|
167
164
|
let mergedOpen = rendered ? innerOpen : false;
|
|
168
165
|
|
|
169
166
|
// Not trigger `open` in `combobox` when `notFoundContent` is empty
|
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 BaseOptionType | DefaultOptionType = 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/Select.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _useControlledState = _interopRequireDefault(require("@rc-component/util/lib/hooks/useControlledState"));
|
|
8
8
|
var _warning = _interopRequireDefault(require("@rc-component/util/lib/warning"));
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _BaseSelect = _interopRequireWildcard(require("./BaseSelect"));
|
|
@@ -134,10 +134,8 @@ const Select = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
134
134
|
/* eslint-enable react-hooks/exhaustive-deps */);
|
|
135
135
|
|
|
136
136
|
// =========================== Search ===========================
|
|
137
|
-
const [
|
|
138
|
-
|
|
139
|
-
postState: search => search || ''
|
|
140
|
-
});
|
|
137
|
+
const [internalSearchValue, setSearchValue] = (0, _useControlledState.default)('', searchValue);
|
|
138
|
+
const mergedSearchValue = internalSearchValue || '';
|
|
141
139
|
|
|
142
140
|
// =========================== Option ===========================
|
|
143
141
|
const parsedOptions = (0, _useOptions.default)(options, children, mergedFieldNames, optionFilterProp, optionLabelProp);
|
|
@@ -192,9 +190,7 @@ const Select = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
192
190
|
}, [mergedFieldNames, optionLabelProp, valueOptions]);
|
|
193
191
|
|
|
194
192
|
// =========================== Values ===========================
|
|
195
|
-
const [internalValue, setInternalValue] = (0,
|
|
196
|
-
value
|
|
197
|
-
});
|
|
193
|
+
const [internalValue, setInternalValue] = (0, _useControlledState.default)(defaultValue, value);
|
|
198
194
|
|
|
199
195
|
// Merged value with LabelValueType
|
|
200
196
|
const rawLabeledValues = React.useMemo(() => {
|
|
@@ -17,15 +17,24 @@ function useDelayReset(timeout = 10) {
|
|
|
17
17
|
const cancelLatest = () => {
|
|
18
18
|
window.clearTimeout(delayRef.current);
|
|
19
19
|
};
|
|
20
|
-
React.useEffect(() =>
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
return () => {
|
|
22
|
+
cancelLatest();
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
21
25
|
const delaySetBool = (value, callback) => {
|
|
22
26
|
cancelLatest();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
if (value === true) {
|
|
28
|
+
// true 值立即设置
|
|
29
|
+
setBool(true);
|
|
30
|
+
callback?.();
|
|
31
|
+
} else {
|
|
32
|
+
// false 值延迟设置
|
|
33
|
+
delayRef.current = window.setTimeout(() => {
|
|
34
|
+
setBool(false);
|
|
35
|
+
callback?.();
|
|
36
|
+
}, timeout);
|
|
37
|
+
}
|
|
29
38
|
};
|
|
30
39
|
return [bool, delaySetBool, cancelLatest];
|
|
31
40
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rc-component/select",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "React Select",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.x"
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@rc-component/trigger": "^3.0.0",
|
|
53
53
|
"@rc-component/motion": "^1.1.4",
|
|
54
|
-
"@rc-component/util": "^1.
|
|
54
|
+
"@rc-component/util": "^1.3.0",
|
|
55
55
|
"classnames": "2.x",
|
|
56
56
|
"rc-overflow": "^1.4.0",
|
|
57
57
|
"rc-virtual-list": "^3.5.2"
|