@autobest-ui/components 2.0.5-alpha.1 → 2.0.5-y.1
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/esm/select/index.d.ts +8 -4
- package/esm/select/index.js +54 -29
- package/lib/select/index.d.ts +8 -4
- package/lib/select/index.js +54 -29
- package/package.json +2 -2
package/esm/select/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface SelectProps extends Pick<TriggerProps, 'windowResizeHidden' | '
|
|
|
21
21
|
* 选择的值
|
|
22
22
|
*/
|
|
23
23
|
value: Value;
|
|
24
|
-
onChange: (item: SelectOptionItem, name?: string
|
|
24
|
+
onChange: (item: SelectOptionItem, name?: string) => void;
|
|
25
25
|
/**
|
|
26
26
|
* 组件标识符
|
|
27
27
|
*/
|
|
@@ -62,6 +62,10 @@ export interface SelectProps extends Pick<TriggerProps, 'windowResizeHidden' | '
|
|
|
62
62
|
* 是否支持过滤功能, 目前的过滤类似carid.com,仅仅支持首字母过滤,滚动到匹配位置,填充匹配到的第一项,触发onChange
|
|
63
63
|
*/
|
|
64
64
|
isFilterOption?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* 过滤到结果时才触发,此时并不会触发onChange, 当点击选项或者隐藏列表后才会触发onChange
|
|
67
|
+
*/
|
|
68
|
+
onFilterChange?: (item: SelectOptionItem, name?: string) => void;
|
|
65
69
|
/**
|
|
66
70
|
* 是否最大全宽
|
|
67
71
|
*/
|
|
@@ -90,12 +94,12 @@ export interface SelectProps extends Pick<TriggerProps, 'windowResizeHidden' | '
|
|
|
90
94
|
interface SelectStates {
|
|
91
95
|
visible: boolean;
|
|
92
96
|
list: [SelectOptionItem[]];
|
|
97
|
+
filterItem?: SelectOptionItem;
|
|
93
98
|
}
|
|
94
99
|
declare class Select extends React.Component<SelectProps, SelectStates> {
|
|
95
100
|
prefixCls: string;
|
|
96
101
|
keydownHandler: AddListenerEventHandler;
|
|
97
102
|
popupContentRef: React.RefObject<HTMLDivElement>;
|
|
98
|
-
isFromFilterSelected: boolean;
|
|
99
103
|
static defaultProps: {
|
|
100
104
|
title: any;
|
|
101
105
|
icon: JSX.Element;
|
|
@@ -106,20 +110,20 @@ declare class Select extends React.Component<SelectProps, SelectStates> {
|
|
|
106
110
|
disabled: boolean;
|
|
107
111
|
hiddenIcon: boolean;
|
|
108
112
|
isMinRootWidth: boolean;
|
|
113
|
+
isFilterOption: boolean;
|
|
109
114
|
isMaxRootWidth: boolean;
|
|
110
115
|
};
|
|
111
116
|
constructor(props: any);
|
|
112
117
|
static getDerivedStateFromProps(nextProps: SelectProps): {
|
|
113
118
|
list: any[];
|
|
114
119
|
};
|
|
115
|
-
componentDidUpdate(prevProps: Readonly<SelectProps>): void;
|
|
116
120
|
componentWillUnmount(): void;
|
|
117
121
|
/**
|
|
118
122
|
* 当支持过滤时,绑定过滤事件
|
|
119
123
|
*/
|
|
120
124
|
addKeydownListener: () => void;
|
|
121
125
|
removeKeydownListener: () => void;
|
|
122
|
-
|
|
126
|
+
keydownCallback: (event: React.KeyboardEvent) => void;
|
|
123
127
|
findMatchItem: (inputVal: string) => SelectOptionItem;
|
|
124
128
|
/**
|
|
125
129
|
* 设置显示与隐藏
|
package/esm/select/index.js
CHANGED
|
@@ -86,7 +86,7 @@ function (_super) {
|
|
|
86
86
|
*/
|
|
87
87
|
|
|
88
88
|
_this.addKeydownListener = function () {
|
|
89
|
-
_this.keydownHandler = addEventListener(document, 'keydown', _this.
|
|
89
|
+
_this.keydownHandler = addEventListener(document, 'keydown', _this.keydownCallback);
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
_this.removeKeydownListener = function () {
|
|
@@ -97,24 +97,40 @@ function (_super) {
|
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
99
|
|
|
100
|
-
_this.
|
|
100
|
+
_this.keydownCallback = function (event) {
|
|
101
101
|
var code = event.keyCode || event.which;
|
|
102
102
|
|
|
103
103
|
if (code >= 65 && code <= 90 || code >= 48 && code <= 57 || code >= 96 && code <= 105) {
|
|
104
|
-
var
|
|
104
|
+
var findItem_1 = _this.findMatchItem(event.key);
|
|
105
105
|
|
|
106
|
-
if (!
|
|
106
|
+
if (!findItem_1) {
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
var _a = _this.props,
|
|
111
|
-
|
|
112
|
-
value = _a.value,
|
|
111
|
+
onFilterChange_1 = _a.onFilterChange,
|
|
113
112
|
name_1 = _a.name;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
var filterItem = _this.state.filterItem;
|
|
114
|
+
|
|
115
|
+
if (!filterItem || findItem_1.value !== filterItem.value) {
|
|
116
|
+
_this.setState({
|
|
117
|
+
filterItem: findItem_1
|
|
118
|
+
}, function () {
|
|
119
|
+
if (onFilterChange_1) {
|
|
120
|
+
onFilterChange_1(findItem_1, name_1);
|
|
121
|
+
} // 通过搜索选择的,将滚动到该元素位置
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
var element = _this.popupContentRef.current;
|
|
125
|
+
|
|
126
|
+
if (element) {
|
|
127
|
+
var activeElement = element.querySelector(".".concat(_this.prefixCls, "-active"));
|
|
128
|
+
activeElement.scrollIntoView({
|
|
129
|
+
block: 'nearest',
|
|
130
|
+
inline: 'start'
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
118
134
|
}
|
|
119
135
|
}
|
|
120
136
|
};
|
|
@@ -154,6 +170,19 @@ function (_super) {
|
|
|
154
170
|
_this.addKeydownListener();
|
|
155
171
|
}
|
|
156
172
|
|
|
173
|
+
var filterItem = _this.state.filterItem;
|
|
174
|
+
|
|
175
|
+
if (filterItem) {
|
|
176
|
+
// 清空filter数据,并触发onChange
|
|
177
|
+
_this.setState({
|
|
178
|
+
filterItem: null
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
if (filterItem.value !== _this.props.value) {
|
|
182
|
+
_this.props.onChange(filterItem, _this.props.name);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
157
186
|
_this.setState({
|
|
158
187
|
visible: status
|
|
159
188
|
});
|
|
@@ -200,27 +229,13 @@ function (_super) {
|
|
|
200
229
|
};
|
|
201
230
|
};
|
|
202
231
|
|
|
203
|
-
Select.prototype.componentDidUpdate = function (prevProps) {
|
|
204
|
-
// 通过搜索选择的,将滚动到该元素位置
|
|
205
|
-
if (this.state.visible && this.isFromFilterSelected && this.props.isFilterOption && prevProps.value !== this.props.value) {
|
|
206
|
-
this.isFromFilterSelected = false;
|
|
207
|
-
var element = this.popupContentRef.current;
|
|
208
|
-
|
|
209
|
-
if (element) {
|
|
210
|
-
var activeElement = element.querySelector(".".concat(this.prefixCls, "-active"));
|
|
211
|
-
activeElement.scrollIntoView({
|
|
212
|
-
block: 'nearest',
|
|
213
|
-
inline: 'start'
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
|
|
219
232
|
Select.prototype.componentWillUnmount = function () {
|
|
220
233
|
this.removeKeydownListener();
|
|
221
234
|
};
|
|
222
235
|
|
|
223
236
|
Select.prototype.onSelecting = function (ev, item) {
|
|
237
|
+
var _this = this;
|
|
238
|
+
|
|
224
239
|
if (ev) {
|
|
225
240
|
ev.stopPropagation();
|
|
226
241
|
}
|
|
@@ -232,6 +247,13 @@ function (_super) {
|
|
|
232
247
|
|
|
233
248
|
if (item.value !== value) {
|
|
234
249
|
onChange(item, name);
|
|
250
|
+
this.setState({
|
|
251
|
+
// select优先级最高,清空filter项
|
|
252
|
+
filterItem: null
|
|
253
|
+
}, function () {
|
|
254
|
+
_this.triggerSelect(false);
|
|
255
|
+
});
|
|
256
|
+
return;
|
|
235
257
|
}
|
|
236
258
|
|
|
237
259
|
this.triggerSelect(false);
|
|
@@ -271,6 +293,7 @@ function (_super) {
|
|
|
271
293
|
var _this = this;
|
|
272
294
|
|
|
273
295
|
var cls = this.prefixCls;
|
|
296
|
+
var filterItem = this.state.filterItem;
|
|
274
297
|
return /*#__PURE__*/React.createElement(React.Fragment, null, this.renderTitle(), /*#__PURE__*/React.createElement("div", {
|
|
275
298
|
className: "".concat(cls, "-content"),
|
|
276
299
|
ref: this.popupContentRef
|
|
@@ -290,7 +313,7 @@ function (_super) {
|
|
|
290
313
|
|
|
291
314
|
return /*#__PURE__*/React.createElement("li", {
|
|
292
315
|
key: item.value,
|
|
293
|
-
className: classNames(item.className, (_a = {}, _a["".concat(cls, "-active")] = item.value === _this.props.value, _a)),
|
|
316
|
+
className: classNames(item.className, (_a = {}, _a["".concat(cls, "-active")] = filterItem ? filterItem.value === item.value : item.value === _this.props.value, _a)),
|
|
294
317
|
onClick: function onClick(ev) {
|
|
295
318
|
return _this.onSelecting(ev, item);
|
|
296
319
|
}
|
|
@@ -308,10 +331,11 @@ function (_super) {
|
|
|
308
331
|
var _a = this.props,
|
|
309
332
|
options = _a.options,
|
|
310
333
|
value = _a.value;
|
|
334
|
+
var filterItem = this.state.filterItem;
|
|
311
335
|
|
|
312
|
-
if (!isBlank(value)) {
|
|
336
|
+
if (!isBlank(value) || filterItem) {
|
|
313
337
|
var currentItem = options.find(function (item) {
|
|
314
|
-
return item.value === value;
|
|
338
|
+
return filterItem ? filterItem.value === item.value : item.value === value;
|
|
315
339
|
});
|
|
316
340
|
|
|
317
341
|
if (currentItem) {
|
|
@@ -378,6 +402,7 @@ function (_super) {
|
|
|
378
402
|
disabled: false,
|
|
379
403
|
hiddenIcon: false,
|
|
380
404
|
isMinRootWidth: false,
|
|
405
|
+
isFilterOption: true,
|
|
381
406
|
isMaxRootWidth: false
|
|
382
407
|
};
|
|
383
408
|
return Select;
|
package/lib/select/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface SelectProps extends Pick<TriggerProps, 'windowResizeHidden' | '
|
|
|
21
21
|
* 选择的值
|
|
22
22
|
*/
|
|
23
23
|
value: Value;
|
|
24
|
-
onChange: (item: SelectOptionItem, name?: string
|
|
24
|
+
onChange: (item: SelectOptionItem, name?: string) => void;
|
|
25
25
|
/**
|
|
26
26
|
* 组件标识符
|
|
27
27
|
*/
|
|
@@ -62,6 +62,10 @@ export interface SelectProps extends Pick<TriggerProps, 'windowResizeHidden' | '
|
|
|
62
62
|
* 是否支持过滤功能, 目前的过滤类似carid.com,仅仅支持首字母过滤,滚动到匹配位置,填充匹配到的第一项,触发onChange
|
|
63
63
|
*/
|
|
64
64
|
isFilterOption?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* 过滤到结果时才触发,此时并不会触发onChange, 当点击选项或者隐藏列表后才会触发onChange
|
|
67
|
+
*/
|
|
68
|
+
onFilterChange?: (item: SelectOptionItem, name?: string) => void;
|
|
65
69
|
/**
|
|
66
70
|
* 是否最大全宽
|
|
67
71
|
*/
|
|
@@ -90,12 +94,12 @@ export interface SelectProps extends Pick<TriggerProps, 'windowResizeHidden' | '
|
|
|
90
94
|
interface SelectStates {
|
|
91
95
|
visible: boolean;
|
|
92
96
|
list: [SelectOptionItem[]];
|
|
97
|
+
filterItem?: SelectOptionItem;
|
|
93
98
|
}
|
|
94
99
|
declare class Select extends React.Component<SelectProps, SelectStates> {
|
|
95
100
|
prefixCls: string;
|
|
96
101
|
keydownHandler: AddListenerEventHandler;
|
|
97
102
|
popupContentRef: React.RefObject<HTMLDivElement>;
|
|
98
|
-
isFromFilterSelected: boolean;
|
|
99
103
|
static defaultProps: {
|
|
100
104
|
title: any;
|
|
101
105
|
icon: JSX.Element;
|
|
@@ -106,20 +110,20 @@ declare class Select extends React.Component<SelectProps, SelectStates> {
|
|
|
106
110
|
disabled: boolean;
|
|
107
111
|
hiddenIcon: boolean;
|
|
108
112
|
isMinRootWidth: boolean;
|
|
113
|
+
isFilterOption: boolean;
|
|
109
114
|
isMaxRootWidth: boolean;
|
|
110
115
|
};
|
|
111
116
|
constructor(props: any);
|
|
112
117
|
static getDerivedStateFromProps(nextProps: SelectProps): {
|
|
113
118
|
list: any[];
|
|
114
119
|
};
|
|
115
|
-
componentDidUpdate(prevProps: Readonly<SelectProps>): void;
|
|
116
120
|
componentWillUnmount(): void;
|
|
117
121
|
/**
|
|
118
122
|
* 当支持过滤时,绑定过滤事件
|
|
119
123
|
*/
|
|
120
124
|
addKeydownListener: () => void;
|
|
121
125
|
removeKeydownListener: () => void;
|
|
122
|
-
|
|
126
|
+
keydownCallback: (event: React.KeyboardEvent) => void;
|
|
123
127
|
findMatchItem: (inputVal: string) => SelectOptionItem;
|
|
124
128
|
/**
|
|
125
129
|
* 设置显示与隐藏
|
package/lib/select/index.js
CHANGED
|
@@ -98,7 +98,7 @@ function (_super) {
|
|
|
98
98
|
*/
|
|
99
99
|
|
|
100
100
|
_this.addKeydownListener = function () {
|
|
101
|
-
_this.keydownHandler = (0, _utils.addEventListener)(document, 'keydown', _this.
|
|
101
|
+
_this.keydownHandler = (0, _utils.addEventListener)(document, 'keydown', _this.keydownCallback);
|
|
102
102
|
};
|
|
103
103
|
|
|
104
104
|
_this.removeKeydownListener = function () {
|
|
@@ -109,24 +109,40 @@ function (_super) {
|
|
|
109
109
|
}
|
|
110
110
|
};
|
|
111
111
|
|
|
112
|
-
_this.
|
|
112
|
+
_this.keydownCallback = function (event) {
|
|
113
113
|
var code = event.keyCode || event.which;
|
|
114
114
|
|
|
115
115
|
if (code >= 65 && code <= 90 || code >= 48 && code <= 57 || code >= 96 && code <= 105) {
|
|
116
|
-
var
|
|
116
|
+
var findItem_1 = _this.findMatchItem(event.key);
|
|
117
117
|
|
|
118
|
-
if (!
|
|
118
|
+
if (!findItem_1) {
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
var _a = _this.props,
|
|
123
|
-
|
|
124
|
-
value = _a.value,
|
|
123
|
+
onFilterChange_1 = _a.onFilterChange,
|
|
125
124
|
name_1 = _a.name;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
var filterItem = _this.state.filterItem;
|
|
126
|
+
|
|
127
|
+
if (!filterItem || findItem_1.value !== filterItem.value) {
|
|
128
|
+
_this.setState({
|
|
129
|
+
filterItem: findItem_1
|
|
130
|
+
}, function () {
|
|
131
|
+
if (onFilterChange_1) {
|
|
132
|
+
onFilterChange_1(findItem_1, name_1);
|
|
133
|
+
} // 通过搜索选择的,将滚动到该元素位置
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
var element = _this.popupContentRef.current;
|
|
137
|
+
|
|
138
|
+
if (element) {
|
|
139
|
+
var activeElement = element.querySelector(".".concat(_this.prefixCls, "-active"));
|
|
140
|
+
activeElement.scrollIntoView({
|
|
141
|
+
block: 'nearest',
|
|
142
|
+
inline: 'start'
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
});
|
|
130
146
|
}
|
|
131
147
|
}
|
|
132
148
|
};
|
|
@@ -166,6 +182,19 @@ function (_super) {
|
|
|
166
182
|
_this.addKeydownListener();
|
|
167
183
|
}
|
|
168
184
|
|
|
185
|
+
var filterItem = _this.state.filterItem;
|
|
186
|
+
|
|
187
|
+
if (filterItem) {
|
|
188
|
+
// 清空filter数据,并触发onChange
|
|
189
|
+
_this.setState({
|
|
190
|
+
filterItem: null
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
if (filterItem.value !== _this.props.value) {
|
|
194
|
+
_this.props.onChange(filterItem, _this.props.name);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
169
198
|
_this.setState({
|
|
170
199
|
visible: status
|
|
171
200
|
});
|
|
@@ -212,27 +241,13 @@ function (_super) {
|
|
|
212
241
|
};
|
|
213
242
|
};
|
|
214
243
|
|
|
215
|
-
Select.prototype.componentDidUpdate = function (prevProps) {
|
|
216
|
-
// 通过搜索选择的,将滚动到该元素位置
|
|
217
|
-
if (this.state.visible && this.isFromFilterSelected && this.props.isFilterOption && prevProps.value !== this.props.value) {
|
|
218
|
-
this.isFromFilterSelected = false;
|
|
219
|
-
var element = this.popupContentRef.current;
|
|
220
|
-
|
|
221
|
-
if (element) {
|
|
222
|
-
var activeElement = element.querySelector(".".concat(this.prefixCls, "-active"));
|
|
223
|
-
activeElement.scrollIntoView({
|
|
224
|
-
block: 'nearest',
|
|
225
|
-
inline: 'start'
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
|
|
231
244
|
Select.prototype.componentWillUnmount = function () {
|
|
232
245
|
this.removeKeydownListener();
|
|
233
246
|
};
|
|
234
247
|
|
|
235
248
|
Select.prototype.onSelecting = function (ev, item) {
|
|
249
|
+
var _this = this;
|
|
250
|
+
|
|
236
251
|
if (ev) {
|
|
237
252
|
ev.stopPropagation();
|
|
238
253
|
}
|
|
@@ -244,6 +259,13 @@ function (_super) {
|
|
|
244
259
|
|
|
245
260
|
if (item.value !== value) {
|
|
246
261
|
onChange(item, name);
|
|
262
|
+
this.setState({
|
|
263
|
+
// select优先级最高,清空filter项
|
|
264
|
+
filterItem: null
|
|
265
|
+
}, function () {
|
|
266
|
+
_this.triggerSelect(false);
|
|
267
|
+
});
|
|
268
|
+
return;
|
|
247
269
|
}
|
|
248
270
|
|
|
249
271
|
this.triggerSelect(false);
|
|
@@ -285,6 +307,7 @@ function (_super) {
|
|
|
285
307
|
var _this = this;
|
|
286
308
|
|
|
287
309
|
var cls = this.prefixCls;
|
|
310
|
+
var filterItem = this.state.filterItem;
|
|
288
311
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, this.renderTitle(), /*#__PURE__*/_react.default.createElement("div", {
|
|
289
312
|
className: "".concat(cls, "-content"),
|
|
290
313
|
ref: this.popupContentRef
|
|
@@ -304,7 +327,7 @@ function (_super) {
|
|
|
304
327
|
|
|
305
328
|
return /*#__PURE__*/_react.default.createElement("li", {
|
|
306
329
|
key: item.value,
|
|
307
|
-
className: (0, _classnames.default)(item.className, (_a = {}, _a["".concat(cls, "-active")] = item.value === _this.props.value, _a)),
|
|
330
|
+
className: (0, _classnames.default)(item.className, (_a = {}, _a["".concat(cls, "-active")] = filterItem ? filterItem.value === item.value : item.value === _this.props.value, _a)),
|
|
308
331
|
onClick: function onClick(ev) {
|
|
309
332
|
return _this.onSelecting(ev, item);
|
|
310
333
|
}
|
|
@@ -322,10 +345,11 @@ function (_super) {
|
|
|
322
345
|
var _a = this.props,
|
|
323
346
|
options = _a.options,
|
|
324
347
|
value = _a.value;
|
|
348
|
+
var filterItem = this.state.filterItem;
|
|
325
349
|
|
|
326
|
-
if (!(0, _utils.isBlank)(value)) {
|
|
350
|
+
if (!(0, _utils.isBlank)(value) || filterItem) {
|
|
327
351
|
var currentItem = options.find(function (item) {
|
|
328
|
-
return item.value === value;
|
|
352
|
+
return filterItem ? filterItem.value === item.value : item.value === value;
|
|
329
353
|
});
|
|
330
354
|
|
|
331
355
|
if (currentItem) {
|
|
@@ -392,6 +416,7 @@ function (_super) {
|
|
|
392
416
|
disabled: false,
|
|
393
417
|
hiddenIcon: false,
|
|
394
418
|
isMinRootWidth: false,
|
|
419
|
+
isFilterOption: true,
|
|
395
420
|
isMaxRootWidth: false
|
|
396
421
|
};
|
|
397
422
|
return Select;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autobest-ui/components",
|
|
3
|
-
"version": "2.0.5-
|
|
3
|
+
"version": "2.0.5-y.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "components common ui for React",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"react": ">=16.8.6",
|
|
47
47
|
"react-transition-group": ">=4.2.2"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "b1bdd28e78a696af37cd63e3f13dd1f96e534ad7"
|
|
50
50
|
}
|