rsuite 4.10.8 → 4.11.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.
@@ -567,45 +567,65 @@ describe('CheckTreePicker', () => {
567
567
  4
568
568
  );
569
569
  });
570
- it('Should expand when has props defaultExpandAll and data change', () => {
571
- const Wrapper = React.forwardRef((props, ref) => {
572
- const nextData = [
573
- {
574
- label: 'Fujian',
575
- value: 3,
576
- children: [
577
- {
578
- label: 'Fuzhou',
579
- value: 36
580
- }
581
- ]
582
- },
583
- {
584
- label: 'Guangdong',
585
- value: 4,
586
- children: [
587
- {
588
- label: 'Guangzhou',
589
- value: 45
590
- }
591
- ]
592
- }
593
- ];
594
- const [willChangeData, setData] = useState(data);
595
- const handleClick = () => {
596
- setData(nextData);
570
+
571
+ describe('data change', () => {
572
+ const renderStart = () => {
573
+ const containerRef = React.createRef();
574
+ const Wrapper = () => {
575
+ const nextData = [
576
+ {
577
+ label: 'Fujian',
578
+ value: 3,
579
+ children: [
580
+ {
581
+ label: 'Fuzhou',
582
+ value: 36
583
+ }
584
+ ]
585
+ },
586
+ {
587
+ label: 'Guangdong',
588
+ value: 4,
589
+ children: [
590
+ {
591
+ label: 'Guangzhou',
592
+ value: 45
593
+ }
594
+ ]
595
+ }
596
+ ];
597
+ const [willChangeData, setData] = useState(data);
598
+ const handleClick = () => {
599
+ setData(nextData);
600
+ };
601
+ return (
602
+ <div ref={containerRef}>
603
+ <button onClick={handleClick} className="change-data">
604
+ change data
605
+ </button>
606
+ <CheckTreePicker inline defaultExpandAll data={willChangeData} />
607
+ </div>
608
+ );
597
609
  };
598
- return (
599
- <div ref={ref}>
600
- <button onClick={handleClick} className="change-data">
601
- change data
602
- </button>
603
- <CheckTreePicker inline defaultExpandAll data={willChangeData} />
604
- </div>
605
- );
610
+ ReactTestUtils.act(() => {
611
+ ReactDOM.render(<Wrapper />, container);
612
+ });
613
+ return containerRef.current;
614
+ };
615
+
616
+ it('Should expand when has props defaultExpandAll', () => {
617
+ const container = renderStart();
618
+ ReactTestUtils.Simulate.click(container.querySelector('.change-data'));
619
+ expect(container.querySelectorAll('.rs-check-tree-open').length).to.equal(2);
620
+ });
621
+
622
+ it('Should be all closed, when click close icon', () => {
623
+ const container = renderStart();
624
+ ReactTestUtils.Simulate.click(container.querySelector('.change-data'));
625
+ container.querySelectorAll('.rs-check-tree-node-expand-icon').forEach(element => {
626
+ ReactTestUtils.Simulate.click(element);
627
+ });
628
+ expect(container.querySelectorAll('.rs-check-tree-open').length).to.equal(0);
606
629
  });
607
- const instance = getDOMNode(<Wrapper />);
608
- ReactTestUtils.Simulate.click(instance.querySelector('.change-data'));
609
- expect(instance.querySelectorAll('.rs-check-tree-open').length).to.equal(2);
610
630
  });
611
631
  });
@@ -1,10 +1,10 @@
1
1
  import * as React from 'react';
2
2
 
3
3
  import { FormControlPickerProps } from '../@types/common';
4
- import { SelectProps } from '../SelectPicker/SelectPicker.d';
4
+ import { BaseSelectProps } from '../SelectPicker/SelectPicker.d';
5
5
  import { TagProps } from '../Tag/Tag.d';
6
6
 
7
- export interface InputPickerProps extends FormControlPickerProps<any>, SelectProps<any> {
7
+ export interface InputPickerProps extends FormControlPickerProps<any>, BaseSelectProps {
8
8
  /** Settings can create new options */
9
9
  creatable?: boolean;
10
10
 
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import { FormControlPickerProps, ItemDataType } from '../@types/common';
4
4
  import { ListProps } from 'react-virtualized/dist/commonjs/List';
5
5
 
6
- export interface SelectProps<ValueType = any> {
6
+ export interface BaseSelectProps {
7
7
  /** Set group condition key in data */
8
8
  groupBy?: string;
9
9
 
@@ -22,13 +22,6 @@ export interface SelectProps<ValueType = any> {
22
22
  /** Custom render menu group */
23
23
  renderMenuGroup?: (title: React.ReactNode, item: ItemDataType) => React.ReactNode;
24
24
 
25
- /** Custom render selected items */
26
- renderValue?: (
27
- value: ValueType,
28
- item: ItemDataType | ItemDataType[],
29
- selectedElement: React.ReactNode
30
- ) => React.ReactNode;
31
-
32
25
  /** Called when the option is selected */
33
26
  onSelect?: (value: any, item: ItemDataType, event: React.SyntheticEvent<any>) => void;
34
27
 
@@ -36,7 +29,7 @@ export interface SelectProps<ValueType = any> {
36
29
  onGroupTitleClick?: (event: React.SyntheticEvent<any>) => void;
37
30
 
38
31
  /** Called when searching */
39
- onSearch?: (searchKeyword: string, event: React.SyntheticEvent<any>) => void;
32
+ onSearch?: (searchKeyword: string, event?: React.SyntheticEvent<any>) => void;
40
33
 
41
34
  /** Called when clean */
42
35
  onClean?: (event: React.SyntheticEvent<any>) => void;
@@ -53,6 +46,14 @@ export interface SelectProps<ValueType = any> {
53
46
  /** Custom search rules. */
54
47
  searchBy?: (keyword: string, label: React.ReactNode, item: ItemDataType) => boolean;
55
48
  }
49
+ export interface SelectProps<ValueType> extends BaseSelectProps {
50
+ /** Custom render selected items */
51
+ renderValue?: (
52
+ value: ValueType,
53
+ item: ItemDataType,
54
+ selectedElement: React.ReactNode
55
+ ) => React.ReactNode;
56
+ }
56
57
 
57
58
  export interface SelectPickerProps extends FormControlPickerProps<any>, SelectProps<any> {}
58
59
 
@@ -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, useRef } 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,59 @@ describe('SelectPicker', () => {
324
337
  assert.equal(list.length, 1);
325
338
  assert.ok(list[0].innerText, 'Louisa');
326
339
  });
340
+
341
+ it('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 = () => {
348
+ const [search, setSearch] = useState(searchRef);
349
+ const containerRef = useRef();
350
+ searchRef = search;
351
+ const handleSearch = value => {
352
+ setSearch(value);
353
+ };
354
+ const handleClose = () => {
355
+ onClose();
356
+ };
357
+ return (
358
+ <div ref={containerRef}>
359
+ <button id="exit">exit</button>
360
+ <Dropdown
361
+ container={() => containerRef.current}
362
+ search={search}
363
+ defaultOpen
364
+ onClose={handleClose}
365
+ onSearch={handleSearch}
366
+ data={data}
367
+ />
368
+ </div>
369
+ );
370
+ };
371
+ Wrapper.displayName = 'WrapperSelectPicker';
372
+ ReactTestUtils.act(() => {
373
+ ReactDOM.render(<Wrapper />, container);
374
+ });
375
+
376
+ const exit = container?.querySelector('#exit');
377
+ const input = container.querySelector(searchInputClassName);
378
+
379
+ // change search
380
+ input.value = 'a';
381
+ ReactTestUtils.Simulate.change(input);
382
+ assert.equal(searchRef, 'a');
383
+
384
+ ReactTestUtils.act(() => {
385
+ // close select
386
+ // ReactTestUtils can't trigger document click event
387
+ exit.dispatchEvent(new MouseEvent('click', { bubbles: true }));
388
+ });
389
+
390
+ promise.then(() => {
391
+ assert.equal(searchRef, '');
392
+ done();
393
+ });
394
+ });
327
395
  });
@@ -1,10 +1,10 @@
1
1
  import * as React from 'react';
2
2
 
3
- import { FormControlPickerProps } from '../@types/common';
4
- import { SelectProps } from '../SelectPicker/SelectPicker.d';
3
+ import { FormControlPickerProps, ItemDataType } from '../@types/common';
4
+ import { BaseSelectProps } from '../SelectPicker/SelectPicker.d';
5
5
  import { TagProps } from '../Tag/Tag.d';
6
6
 
7
- export interface TagPickerProps extends FormControlPickerProps, SelectProps<any[]> {
7
+ export interface TagPickerProps extends FormControlPickerProps, BaseSelectProps {
8
8
  /** Option to cache value when searching asynchronously */
9
9
  cacheData?: any[];
10
10
 
@@ -16,6 +16,13 @@ export interface TagPickerProps extends FormControlPickerProps, SelectProps<any[
16
16
  * https://github.com/rsuite/rsuite/blob/master/src/Tag/Tag.d.ts
17
17
  */
18
18
  tagProps?: TagProps;
19
+
20
+ /** Custom render selected items */
21
+ renderValue?: (
22
+ value: any[],
23
+ item: ItemDataType[],
24
+ selectedElement: React.ReactNode
25
+ ) => React.ReactNode;
19
26
  }
20
27
 
21
28
  declare const TagPicker: React.ComponentType<TagPickerProps>;