@autobest-ui/components 2.0.5-alpha.1 → 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.
@@ -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, isFromFilterSelected?: boolean) => void;
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;
@@ -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, true);
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) {
@@ -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, isFromFilterSelected?: boolean) => void;
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;
@@ -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, true);
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobest-ui/components",
3
- "version": "2.0.5-alpha.1",
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": "25088b80191d4491efa60bf4a36be60d09d7fce1"
49
+ "gitHead": "c8153bfb2dd22ba6d3925d08d86529ef78b7ec53"
50
50
  }