rsuite 4.10.9 → 4.10.10

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.
@@ -36,7 +36,7 @@ export interface SelectProps<ValueType = any> {
36
36
  onGroupTitleClick?: (event: React.SyntheticEvent<any>) => void;
37
37
 
38
38
  /** Called when searching */
39
- onSearch?: (searchKeyword: string, event: React.SyntheticEvent<any>) => void;
39
+ onSearch?: (searchKeyword: string, event?: React.SyntheticEvent<any>) => void;
40
40
 
41
41
  /** Called when clean */
42
42
  onClean?: (event: React.SyntheticEvent<any>) => void;
@@ -239,18 +239,19 @@ function (_React$Component) {
239
239
  };
240
240
 
241
241
  _this.handleExit = function () {
242
- var _this$props$onClose, _this$props6;
242
+ var _this$props$onSearch, _this$props6, _this$props$onClose, _this$props7;
243
243
 
244
244
  _this.setState({
245
245
  searchKeyword: '',
246
246
  active: false
247
247
  });
248
248
 
249
- (_this$props$onClose = (_this$props6 = _this.props).onClose) === null || _this$props$onClose === void 0 ? void 0 : _this$props$onClose.call(_this$props6);
249
+ (_this$props$onSearch = (_this$props6 = _this.props).onSearch) === null || _this$props$onSearch === void 0 ? void 0 : _this$props$onSearch.call(_this$props6, '');
250
+ (_this$props$onClose = (_this$props7 = _this.props).onClose) === null || _this$props$onClose === void 0 ? void 0 : _this$props$onClose.call(_this$props7);
250
251
  };
251
252
 
252
253
  _this.handleOpen = function () {
253
- var _this$props$onOpen, _this$props7;
254
+ var _this$props$onOpen, _this$props8;
254
255
 
255
256
  var value = _this.getValue();
256
257
 
@@ -259,7 +260,7 @@ function (_React$Component) {
259
260
  focusItemValue: value
260
261
  });
261
262
 
262
- (_this$props$onOpen = (_this$props7 = _this.props).onOpen) === null || _this$props$onOpen === void 0 ? void 0 : _this$props$onOpen.call(_this$props7);
263
+ (_this$props$onOpen = (_this$props8 = _this.props).onOpen) === null || _this$props$onOpen === void 0 ? void 0 : _this$props$onOpen.call(_this$props8);
263
264
  };
264
265
 
265
266
  _this.addPrefix = function (name) {
@@ -303,9 +304,9 @@ function (_React$Component) {
303
304
  * @param {node} label
304
305
  */
305
306
  _proto.shouldDisplay = function shouldDisplay(item, word) {
306
- var _this$props8 = this.props,
307
- searchBy = _this$props8.searchBy,
308
- labelKey = _this$props8.labelKey;
307
+ var _this$props9 = this.props,
308
+ searchBy = _this$props9.searchBy,
309
+ labelKey = _this$props9.labelKey;
309
310
  var label = item === null || item === void 0 ? void 0 : item[labelKey];
310
311
  var searchKeyword = typeof word === 'undefined' ? this.state.searchKeyword : word;
311
312
 
@@ -334,18 +335,18 @@ function (_React$Component) {
334
335
  _proto.renderDropdownMenu = function renderDropdownMenu() {
335
336
  var _this4 = this;
336
337
 
337
- var _this$props9 = this.props,
338
- data = _this$props9.data,
339
- groupBy = _this$props9.groupBy,
340
- searchable = _this$props9.searchable,
341
- locale = _this$props9.locale,
342
- renderMenu = _this$props9.renderMenu,
343
- renderExtraFooter = _this$props9.renderExtraFooter,
344
- menuClassName = _this$props9.menuClassName,
345
- menuStyle = _this$props9.menuStyle,
346
- menuAutoWidth = _this$props9.menuAutoWidth,
347
- sort = _this$props9.sort,
348
- virtualized = _this$props9.virtualized;
338
+ var _this$props10 = this.props,
339
+ data = _this$props10.data,
340
+ groupBy = _this$props10.groupBy,
341
+ searchable = _this$props10.searchable,
342
+ locale = _this$props10.locale,
343
+ renderMenu = _this$props10.renderMenu,
344
+ renderExtraFooter = _this$props10.renderExtraFooter,
345
+ menuClassName = _this$props10.menuClassName,
346
+ menuStyle = _this$props10.menuStyle,
347
+ menuAutoWidth = _this$props10.menuAutoWidth,
348
+ sort = _this$props10.sort,
349
+ virtualized = _this$props10.virtualized;
349
350
  var focusItemValue = this.state.focusItemValue;
350
351
  var classes = classNames(this.addPrefix('select-menu'), menuClassName);
351
352
  var filteredData = filterNodesOfTree(data, function (item) {
@@ -390,22 +391,22 @@ function (_React$Component) {
390
391
  };
391
392
 
392
393
  _proto.render = function render() {
393
- var _this$props10 = this.props,
394
- data = _this$props10.data,
395
- valueKey = _this$props10.valueKey,
396
- labelKey = _this$props10.labelKey,
397
- placeholder = _this$props10.placeholder,
398
- renderValue = _this$props10.renderValue,
399
- disabled = _this$props10.disabled,
400
- cleanable = _this$props10.cleanable,
401
- locale = _this$props10.locale,
402
- toggleComponentClass = _this$props10.toggleComponentClass,
403
- style = _this$props10.style,
404
- onEntered = _this$props10.onEntered,
405
- onExited = _this$props10.onExited,
406
- onClean = _this$props10.onClean,
407
- positionRef = _this$props10.positionRef,
408
- rest = _objectWithoutPropertiesLoose(_this$props10, ["data", "valueKey", "labelKey", "placeholder", "renderValue", "disabled", "cleanable", "locale", "toggleComponentClass", "style", "onEntered", "onExited", "onClean", "positionRef"]);
394
+ var _this$props11 = this.props,
395
+ data = _this$props11.data,
396
+ valueKey = _this$props11.valueKey,
397
+ labelKey = _this$props11.labelKey,
398
+ placeholder = _this$props11.placeholder,
399
+ renderValue = _this$props11.renderValue,
400
+ disabled = _this$props11.disabled,
401
+ cleanable = _this$props11.cleanable,
402
+ locale = _this$props11.locale,
403
+ toggleComponentClass = _this$props11.toggleComponentClass,
404
+ style = _this$props11.style,
405
+ onEntered = _this$props11.onEntered,
406
+ onExited = _this$props11.onExited,
407
+ onClean = _this$props11.onClean,
408
+ positionRef = _this$props11.positionRef,
409
+ rest = _objectWithoutPropertiesLoose(_this$props11, ["data", "valueKey", "labelKey", "placeholder", "renderValue", "disabled", "cleanable", "locale", "toggleComponentClass", "style", "onEntered", "onExited", "onClean", "positionRef"]);
409
410
 
410
411
  var unhandled = getUnhandledProps(SelectPicker, rest);
411
412
  var value = this.getValue(); // Find active `MenuItem` by `value`
@@ -36,7 +36,7 @@ export interface SelectProps<ValueType = any> {
36
36
  onGroupTitleClick?: (event: React.SyntheticEvent<any>) => void;
37
37
 
38
38
  /** Called when searching */
39
- onSearch?: (searchKeyword: string, event: React.SyntheticEvent<any>) => void;
39
+ onSearch?: (searchKeyword: string, event?: React.SyntheticEvent<any>) => void;
40
40
 
41
41
  /** Called when clean */
42
42
  onClean?: (event: React.SyntheticEvent<any>) => void;
@@ -264,18 +264,19 @@ function (_React$Component) {
264
264
  };
265
265
 
266
266
  _this.handleExit = function () {
267
- var _this$props$onClose, _this$props6;
267
+ var _this$props$onSearch, _this$props6, _this$props$onClose, _this$props7;
268
268
 
269
269
  _this.setState({
270
270
  searchKeyword: '',
271
271
  active: false
272
272
  });
273
273
 
274
- (_this$props$onClose = (_this$props6 = _this.props).onClose) === null || _this$props$onClose === void 0 ? void 0 : _this$props$onClose.call(_this$props6);
274
+ (_this$props$onSearch = (_this$props6 = _this.props).onSearch) === null || _this$props$onSearch === void 0 ? void 0 : _this$props$onSearch.call(_this$props6, '');
275
+ (_this$props$onClose = (_this$props7 = _this.props).onClose) === null || _this$props$onClose === void 0 ? void 0 : _this$props$onClose.call(_this$props7);
275
276
  };
276
277
 
277
278
  _this.handleOpen = function () {
278
- var _this$props$onOpen, _this$props7;
279
+ var _this$props$onOpen, _this$props8;
279
280
 
280
281
  var value = _this.getValue();
281
282
 
@@ -284,7 +285,7 @@ function (_React$Component) {
284
285
  focusItemValue: value
285
286
  });
286
287
 
287
- (_this$props$onOpen = (_this$props7 = _this.props).onOpen) === null || _this$props$onOpen === void 0 ? void 0 : _this$props$onOpen.call(_this$props7);
288
+ (_this$props$onOpen = (_this$props8 = _this.props).onOpen) === null || _this$props$onOpen === void 0 ? void 0 : _this$props$onOpen.call(_this$props8);
288
289
  };
289
290
 
290
291
  _this.addPrefix = function (name) {
@@ -328,9 +329,9 @@ function (_React$Component) {
328
329
  * @param {node} label
329
330
  */
330
331
  _proto.shouldDisplay = function shouldDisplay(item, word) {
331
- var _this$props8 = this.props,
332
- searchBy = _this$props8.searchBy,
333
- labelKey = _this$props8.labelKey;
332
+ var _this$props9 = this.props,
333
+ searchBy = _this$props9.searchBy,
334
+ labelKey = _this$props9.labelKey;
334
335
  var label = item === null || item === void 0 ? void 0 : item[labelKey];
335
336
  var searchKeyword = typeof word === 'undefined' ? this.state.searchKeyword : word;
336
337
 
@@ -359,18 +360,18 @@ function (_React$Component) {
359
360
  _proto.renderDropdownMenu = function renderDropdownMenu() {
360
361
  var _this4 = this;
361
362
 
362
- var _this$props9 = this.props,
363
- data = _this$props9.data,
364
- groupBy = _this$props9.groupBy,
365
- searchable = _this$props9.searchable,
366
- locale = _this$props9.locale,
367
- renderMenu = _this$props9.renderMenu,
368
- renderExtraFooter = _this$props9.renderExtraFooter,
369
- menuClassName = _this$props9.menuClassName,
370
- menuStyle = _this$props9.menuStyle,
371
- menuAutoWidth = _this$props9.menuAutoWidth,
372
- sort = _this$props9.sort,
373
- virtualized = _this$props9.virtualized;
363
+ var _this$props10 = this.props,
364
+ data = _this$props10.data,
365
+ groupBy = _this$props10.groupBy,
366
+ searchable = _this$props10.searchable,
367
+ locale = _this$props10.locale,
368
+ renderMenu = _this$props10.renderMenu,
369
+ renderExtraFooter = _this$props10.renderExtraFooter,
370
+ menuClassName = _this$props10.menuClassName,
371
+ menuStyle = _this$props10.menuStyle,
372
+ menuAutoWidth = _this$props10.menuAutoWidth,
373
+ sort = _this$props10.sort,
374
+ virtualized = _this$props10.virtualized;
374
375
  var focusItemValue = this.state.focusItemValue;
375
376
  var classes = (0, _classnames.default)(this.addPrefix('select-menu'), menuClassName);
376
377
  var filteredData = (0, _treeUtils.filterNodesOfTree)(data, function (item) {
@@ -414,22 +415,22 @@ function (_React$Component) {
414
415
  };
415
416
 
416
417
  _proto.render = function render() {
417
- var _this$props10 = this.props,
418
- data = _this$props10.data,
419
- valueKey = _this$props10.valueKey,
420
- labelKey = _this$props10.labelKey,
421
- placeholder = _this$props10.placeholder,
422
- renderValue = _this$props10.renderValue,
423
- disabled = _this$props10.disabled,
424
- cleanable = _this$props10.cleanable,
425
- locale = _this$props10.locale,
426
- toggleComponentClass = _this$props10.toggleComponentClass,
427
- style = _this$props10.style,
428
- onEntered = _this$props10.onEntered,
429
- onExited = _this$props10.onExited,
430
- onClean = _this$props10.onClean,
431
- positionRef = _this$props10.positionRef,
432
- rest = (0, _objectWithoutPropertiesLoose2.default)(_this$props10, ["data", "valueKey", "labelKey", "placeholder", "renderValue", "disabled", "cleanable", "locale", "toggleComponentClass", "style", "onEntered", "onExited", "onClean", "positionRef"]);
418
+ var _this$props11 = this.props,
419
+ data = _this$props11.data,
420
+ valueKey = _this$props11.valueKey,
421
+ labelKey = _this$props11.labelKey,
422
+ placeholder = _this$props11.placeholder,
423
+ renderValue = _this$props11.renderValue,
424
+ disabled = _this$props11.disabled,
425
+ cleanable = _this$props11.cleanable,
426
+ locale = _this$props11.locale,
427
+ toggleComponentClass = _this$props11.toggleComponentClass,
428
+ style = _this$props11.style,
429
+ onEntered = _this$props11.onEntered,
430
+ onExited = _this$props11.onExited,
431
+ onClean = _this$props11.onClean,
432
+ positionRef = _this$props11.positionRef,
433
+ rest = (0, _objectWithoutPropertiesLoose2.default)(_this$props11, ["data", "valueKey", "labelKey", "placeholder", "renderValue", "disabled", "cleanable", "locale", "toggleComponentClass", "style", "onEntered", "onExited", "onClean", "positionRef"]);
433
434
  var unhandled = (0, _utils.getUnhandledProps)(SelectPicker, rest);
434
435
  var value = this.getValue(); // Find active `MenuItem` by `value`
435
436
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsuite",
3
- "version": "4.10.9",
3
+ "version": "4.10.10",
4
4
  "description": "A suite of react components",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -36,7 +36,7 @@ export interface SelectProps<ValueType = any> {
36
36
  onGroupTitleClick?: (event: React.SyntheticEvent<any>) => void;
37
37
 
38
38
  /** Called when searching */
39
- onSearch?: (searchKeyword: string, event: React.SyntheticEvent<any>) => void;
39
+ onSearch?: (searchKeyword: string, event?: React.SyntheticEvent<any>) => void;
40
40
 
41
41
  /** Called when clean */
42
42
  onClean?: (event: React.SyntheticEvent<any>) => void;
@@ -282,7 +282,7 @@ class SelectPicker extends React.Component<SelectPickerProps, SelectPickerState>
282
282
  searchKeyword: '',
283
283
  active: false
284
284
  });
285
-
285
+ this.props.onSearch?.('');
286
286
  this.props.onClose?.();
287
287
  };
288
288
 
@@ -1,4 +1,5 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
+ import ReactDOM from 'react-dom';
2
3
  import ReactTestUtils from 'react-dom/test-utils';
3
4
  import { globalKey, getDOMNode, getInstance } from '@test/testUtils';
4
5
 
@@ -34,6 +35,18 @@ const data = [
34
35
  }
35
36
  ];
36
37
 
38
+ let container;
39
+
40
+ beforeEach(() => {
41
+ container = document.createElement('div');
42
+ document.body.appendChild(container);
43
+ });
44
+
45
+ afterEach(() => {
46
+ document.body.removeChild(container);
47
+ container = null;
48
+ });
49
+
37
50
  describe('SelectPicker', () => {
38
51
  it('Should clean selected default value', () => {
39
52
  const instance = getDOMNode(<Dropdown defaultOpen data={data} defaultValue={'Eugenia'} />);
@@ -324,4 +337,57 @@ describe('SelectPicker', () => {
324
337
  assert.equal(list.length, 1);
325
338
  assert.ok(list[0].innerText, 'Louisa');
326
339
  });
340
+
341
+ it.only('SearchWord should be reset when controlled and triggered off', done => {
342
+ let searchRef = '';
343
+ let onClose = null;
344
+ const promise = new Promise(resolve => {
345
+ onClose = resolve;
346
+ });
347
+ const Wrapper = React.forwardRef((props, ref) => {
348
+ const [search, setSearch] = useState(searchRef);
349
+ searchRef = search;
350
+ const handleSearch = value => {
351
+ setSearch(value);
352
+ };
353
+ const handleClose = () => {
354
+ onClose();
355
+ };
356
+ return (
357
+ <div>
358
+ <button id="exit">exit</button>
359
+ <Dropdown
360
+ search={search}
361
+ ref={ref}
362
+ defaultOpen
363
+ onClose={handleClose}
364
+ onSearch={handleSearch}
365
+ data={data}
366
+ />
367
+ </div>
368
+ );
369
+ });
370
+ Wrapper.displayName = 'WrapperSelectPicker';
371
+ ReactTestUtils.act(() => {
372
+ ReactDOM.render(<Wrapper />, container);
373
+ });
374
+
375
+ const exit = container?.querySelector('#exit');
376
+ const input = document.querySelector(searchInputClassName);
377
+ // change search
378
+ input.value = 'a';
379
+ ReactTestUtils.Simulate.change(input);
380
+ assert.equal(searchRef, 'a');
381
+
382
+ ReactTestUtils.act(() => {
383
+ // close select
384
+ // ReactTestUtils can't trigger document click event
385
+ exit.dispatchEvent(new MouseEvent('click', { bubbles: true }));
386
+ });
387
+
388
+ promise.then(() => {
389
+ assert.equal(searchRef, '');
390
+ done();
391
+ });
392
+ });
327
393
  });