@autobest-ui/components 2.0.5-alpha.0 → 2.0.5-y.0

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.
@@ -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;
@@ -112,14 +116,13 @@ declare class Select extends React.Component<SelectProps, SelectStates> {
112
116
  static getDerivedStateFromProps(nextProps: SelectProps): {
113
117
  list: any[];
114
118
  };
115
- componentDidUpdate(prevProps: Readonly<SelectProps>): void;
116
119
  componentWillUnmount(): void;
117
120
  /**
118
121
  * 当支持过滤时,绑定过滤事件
119
122
  */
120
123
  addKeydownListener: () => void;
121
124
  removeKeydownListener: () => void;
122
- KeydownCallback: (event: React.KeyboardEvent) => void;
125
+ keydownCallback: (event: React.KeyboardEvent) => void;
123
126
  findMatchItem: (inputVal: string) => SelectOptionItem;
124
127
  /**
125
128
  * 设置显示与隐藏
@@ -86,7 +86,7 @@ function (_super) {
86
86
  */
87
87
 
88
88
  _this.addKeydownListener = function () {
89
- _this.keydownHandler = addEventListener(document, 'keydown', _this.KeydownCallback);
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.KeydownCallback = function (event) {
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 findItem = _this.findMatchItem(event.key);
104
+ var findItem_1 = _this.findMatchItem(event.key);
105
105
 
106
- if (!findItem) {
106
+ if (!findItem_1) {
107
107
  return;
108
108
  }
109
109
 
110
110
  var _a = _this.props,
111
- onChange = _a.onChange,
112
- value = _a.value,
111
+ onFilterChange_1 = _a.onFilterChange,
113
112
  name_1 = _a.name;
114
-
115
- if (findItem.value !== value) {
116
- _this.isFromFilterSelected = true;
117
- onChange(findItem, name_1);
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,28 +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
- behavior: 'smooth',
213
- block: 'nearest',
214
- inline: 'start'
215
- });
216
- }
217
- }
218
- };
219
-
220
232
  Select.prototype.componentWillUnmount = function () {
221
233
  this.removeKeydownListener();
222
234
  };
223
235
 
224
236
  Select.prototype.onSelecting = function (ev, item) {
237
+ var _this = this;
238
+
225
239
  if (ev) {
226
240
  ev.stopPropagation();
227
241
  }
@@ -233,6 +247,13 @@ function (_super) {
233
247
 
234
248
  if (item.value !== value) {
235
249
  onChange(item, name);
250
+ this.setState({
251
+ // select优先级最高,清空filter项
252
+ filterItem: null
253
+ }, function () {
254
+ _this.triggerSelect(false);
255
+ });
256
+ return;
236
257
  }
237
258
 
238
259
  this.triggerSelect(false);
@@ -272,6 +293,7 @@ function (_super) {
272
293
  var _this = this;
273
294
 
274
295
  var cls = this.prefixCls;
296
+ var filterItem = this.state.filterItem;
275
297
  return /*#__PURE__*/React.createElement(React.Fragment, null, this.renderTitle(), /*#__PURE__*/React.createElement("div", {
276
298
  className: "".concat(cls, "-content"),
277
299
  ref: this.popupContentRef
@@ -291,7 +313,7 @@ function (_super) {
291
313
 
292
314
  return /*#__PURE__*/React.createElement("li", {
293
315
  key: item.value,
294
- 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)),
295
317
  onClick: function onClick(ev) {
296
318
  return _this.onSelecting(ev, item);
297
319
  }
@@ -309,10 +331,11 @@ function (_super) {
309
331
  var _a = this.props,
310
332
  options = _a.options,
311
333
  value = _a.value;
334
+ var filterItem = this.state.filterItem;
312
335
 
313
- if (!isBlank(value)) {
336
+ if (!isBlank(value) || filterItem) {
314
337
  var currentItem = options.find(function (item) {
315
- return item.value === value;
338
+ return filterItem ? filterItem.value === item.value : item.value === value;
316
339
  });
317
340
 
318
341
  if (currentItem) {
@@ -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;
@@ -112,14 +116,13 @@ declare class Select extends React.Component<SelectProps, SelectStates> {
112
116
  static getDerivedStateFromProps(nextProps: SelectProps): {
113
117
  list: any[];
114
118
  };
115
- componentDidUpdate(prevProps: Readonly<SelectProps>): void;
116
119
  componentWillUnmount(): void;
117
120
  /**
118
121
  * 当支持过滤时,绑定过滤事件
119
122
  */
120
123
  addKeydownListener: () => void;
121
124
  removeKeydownListener: () => void;
122
- KeydownCallback: (event: React.KeyboardEvent) => void;
125
+ keydownCallback: (event: React.KeyboardEvent) => void;
123
126
  findMatchItem: (inputVal: string) => SelectOptionItem;
124
127
  /**
125
128
  * 设置显示与隐藏
@@ -98,7 +98,7 @@ function (_super) {
98
98
  */
99
99
 
100
100
  _this.addKeydownListener = function () {
101
- _this.keydownHandler = (0, _utils.addEventListener)(document, 'keydown', _this.KeydownCallback);
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.KeydownCallback = function (event) {
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 findItem = _this.findMatchItem(event.key);
116
+ var findItem_1 = _this.findMatchItem(event.key);
117
117
 
118
- if (!findItem) {
118
+ if (!findItem_1) {
119
119
  return;
120
120
  }
121
121
 
122
122
  var _a = _this.props,
123
- onChange = _a.onChange,
124
- value = _a.value,
123
+ onFilterChange_1 = _a.onFilterChange,
125
124
  name_1 = _a.name;
126
-
127
- if (findItem.value !== value) {
128
- _this.isFromFilterSelected = true;
129
- onChange(findItem, name_1);
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,28 +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
- behavior: 'smooth',
225
- block: 'nearest',
226
- inline: 'start'
227
- });
228
- }
229
- }
230
- };
231
-
232
244
  Select.prototype.componentWillUnmount = function () {
233
245
  this.removeKeydownListener();
234
246
  };
235
247
 
236
248
  Select.prototype.onSelecting = function (ev, item) {
249
+ var _this = this;
250
+
237
251
  if (ev) {
238
252
  ev.stopPropagation();
239
253
  }
@@ -245,6 +259,13 @@ function (_super) {
245
259
 
246
260
  if (item.value !== value) {
247
261
  onChange(item, name);
262
+ this.setState({
263
+ // select优先级最高,清空filter项
264
+ filterItem: null
265
+ }, function () {
266
+ _this.triggerSelect(false);
267
+ });
268
+ return;
248
269
  }
249
270
 
250
271
  this.triggerSelect(false);
@@ -286,6 +307,7 @@ function (_super) {
286
307
  var _this = this;
287
308
 
288
309
  var cls = this.prefixCls;
310
+ var filterItem = this.state.filterItem;
289
311
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, this.renderTitle(), /*#__PURE__*/_react.default.createElement("div", {
290
312
  className: "".concat(cls, "-content"),
291
313
  ref: this.popupContentRef
@@ -305,7 +327,7 @@ function (_super) {
305
327
 
306
328
  return /*#__PURE__*/_react.default.createElement("li", {
307
329
  key: item.value,
308
- 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)),
309
331
  onClick: function onClick(ev) {
310
332
  return _this.onSelecting(ev, item);
311
333
  }
@@ -323,10 +345,11 @@ function (_super) {
323
345
  var _a = this.props,
324
346
  options = _a.options,
325
347
  value = _a.value;
348
+ var filterItem = this.state.filterItem;
326
349
 
327
- if (!(0, _utils.isBlank)(value)) {
350
+ if (!(0, _utils.isBlank)(value) || filterItem) {
328
351
  var currentItem = options.find(function (item) {
329
- return item.value === value;
352
+ return filterItem ? filterItem.value === item.value : item.value === value;
330
353
  });
331
354
 
332
355
  if (currentItem) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobest-ui/components",
3
- "version": "2.0.5-alpha.0",
3
+ "version": "2.0.5-y.0",
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": "441d4fe1f371209bb8d981e5eb1c5e1c52237310"
49
+ "gitHead": "c8153bfb2dd22ba6d3925d08d86529ef78b7ec53"
50
50
  }