rsuite 4.10.1 → 4.10.2
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/CHANGELOG.md +13 -0
- package/dist/rsuite.js +3 -3
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/es/CheckTreePicker/CheckTreePicker.js +8 -7
- package/es/utils/treeUtils.js +5 -1
- package/lib/CheckTreePicker/CheckTreePicker.js +8 -7
- package/lib/utils/treeUtils.js +5 -1
- package/package.json +2 -2
- package/src/CheckTreePicker/CheckTreePicker.tsx +15 -7
- package/src/CheckTreePicker/test/CheckTreePickerSpec.js +184 -1
- package/src/TreePicker/test/TreePickerSpec.js +43 -15
- package/src/utils/treeUtils.ts +4 -1
|
@@ -471,11 +471,11 @@ function (_React$Component) {
|
|
|
471
471
|
nextState.value = value;
|
|
472
472
|
}
|
|
473
473
|
|
|
474
|
-
if (compareArray(expandItemValues, prevState.expandItemValues)) {
|
|
474
|
+
if (compareArray(expandItemValues, prevState.expandItemValues) && _isArray(expandItemValues)) {
|
|
475
475
|
nextState.expandItemValues = expandItemValues;
|
|
476
476
|
}
|
|
477
477
|
|
|
478
|
-
if (compareArray(uncheckableItemValues, prevState.uncheckableItemValues)) {
|
|
478
|
+
if (compareArray(uncheckableItemValues, prevState.uncheckableItemValues) && _isArray(uncheckableItemValues)) {
|
|
479
479
|
nextState.uncheckableItemValues = uncheckableItemValues;
|
|
480
480
|
}
|
|
481
481
|
|
|
@@ -542,7 +542,7 @@ function (_React$Component) {
|
|
|
542
542
|
|
|
543
543
|
if (compareArray(value, prevState.value)) {
|
|
544
544
|
this.unserializeLists({
|
|
545
|
-
check: value,
|
|
545
|
+
check: value !== null && value !== void 0 ? value : [],
|
|
546
546
|
expand: expandItemValues
|
|
547
547
|
});
|
|
548
548
|
this.setState({
|
|
@@ -556,7 +556,7 @@ function (_React$Component) {
|
|
|
556
556
|
_proto.updateExpandItemValuesChange = function updateExpandItemValuesChange(prevState) {
|
|
557
557
|
var expandItemValues = this.props.expandItemValues;
|
|
558
558
|
|
|
559
|
-
if (compareArray(expandItemValues, prevState.expandItemValues)) {
|
|
559
|
+
if (compareArray(expandItemValues, prevState.expandItemValues) && _isArray(expandItemValues)) {
|
|
560
560
|
this.unserializeLists({
|
|
561
561
|
expand: expandItemValues
|
|
562
562
|
});
|
|
@@ -573,7 +573,7 @@ function (_React$Component) {
|
|
|
573
573
|
expandItemValues = _this$state3.expandItemValues;
|
|
574
574
|
var uncheckableItemValues = this.props.uncheckableItemValues;
|
|
575
575
|
|
|
576
|
-
if (compareArray(uncheckableItemValues, prevState.uncheckableItemValues)) {
|
|
576
|
+
if (compareArray(uncheckableItemValues, prevState.uncheckableItemValues) && _isArray(uncheckableItemValues)) {
|
|
577
577
|
this.flattenNodes(data);
|
|
578
578
|
this.unserializeLists({
|
|
579
579
|
check: selectedValues,
|
|
@@ -625,6 +625,7 @@ function (_React$Component) {
|
|
|
625
625
|
|
|
626
626
|
if (isEveryChildChecked(node, this.nodes, this.props)) {
|
|
627
627
|
this.nodes[node.refKey].checkAll = true;
|
|
628
|
+
this.nodes[node.refKey].check = true;
|
|
628
629
|
return CHECK_STATE.CHECK;
|
|
629
630
|
}
|
|
630
631
|
|
|
@@ -844,7 +845,7 @@ function (_React$Component) {
|
|
|
844
845
|
});
|
|
845
846
|
}
|
|
846
847
|
/**
|
|
847
|
-
* 过滤选中的values中不包含 uncheckableItemValues 的那些值
|
|
848
|
+
* 过滤选中的 values 中不包含 uncheckableItemValues 的那些值
|
|
848
849
|
* @param {*} values
|
|
849
850
|
*/
|
|
850
851
|
;
|
|
@@ -1005,7 +1006,7 @@ function (_React$Component) {
|
|
|
1005
1006
|
};
|
|
1006
1007
|
|
|
1007
1008
|
_proto.toggleNode = function toggleNode(key, node, toggleValue) {
|
|
1008
|
-
// 如果该节点处于
|
|
1009
|
+
// 如果该节点处于 disabledCheckbox,则忽略该值
|
|
1009
1010
|
if (!node.uncheckable) {
|
|
1010
1011
|
this.nodes[node.refKey][key] = toggleValue;
|
|
1011
1012
|
}
|
package/es/utils/treeUtils.js
CHANGED
|
@@ -146,7 +146,11 @@ export function treeDeprecatedWarning(props, keys) {
|
|
|
146
146
|
*/
|
|
147
147
|
|
|
148
148
|
export function compareArray(a, b) {
|
|
149
|
-
|
|
149
|
+
if (!(_isArray(a) && _isArray(b))) {
|
|
150
|
+
return a !== b;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return !shallowEqualArray(a, b);
|
|
150
154
|
}
|
|
151
155
|
/**
|
|
152
156
|
* 获取 expandAll 的 value
|
|
@@ -505,11 +505,11 @@ function (_React$Component) {
|
|
|
505
505
|
nextState.value = value;
|
|
506
506
|
}
|
|
507
507
|
|
|
508
|
-
if ((0, _treeUtils.compareArray)(expandItemValues, prevState.expandItemValues)) {
|
|
508
|
+
if ((0, _treeUtils.compareArray)(expandItemValues, prevState.expandItemValues) && (0, _isArray2.default)(expandItemValues)) {
|
|
509
509
|
nextState.expandItemValues = expandItemValues;
|
|
510
510
|
}
|
|
511
511
|
|
|
512
|
-
if ((0, _treeUtils.compareArray)(uncheckableItemValues, prevState.uncheckableItemValues)) {
|
|
512
|
+
if ((0, _treeUtils.compareArray)(uncheckableItemValues, prevState.uncheckableItemValues) && (0, _isArray2.default)(uncheckableItemValues)) {
|
|
513
513
|
nextState.uncheckableItemValues = uncheckableItemValues;
|
|
514
514
|
}
|
|
515
515
|
|
|
@@ -576,7 +576,7 @@ function (_React$Component) {
|
|
|
576
576
|
|
|
577
577
|
if ((0, _treeUtils.compareArray)(value, prevState.value)) {
|
|
578
578
|
this.unserializeLists({
|
|
579
|
-
check: value,
|
|
579
|
+
check: value !== null && value !== void 0 ? value : [],
|
|
580
580
|
expand: expandItemValues
|
|
581
581
|
});
|
|
582
582
|
this.setState({
|
|
@@ -590,7 +590,7 @@ function (_React$Component) {
|
|
|
590
590
|
_proto.updateExpandItemValuesChange = function updateExpandItemValuesChange(prevState) {
|
|
591
591
|
var expandItemValues = this.props.expandItemValues;
|
|
592
592
|
|
|
593
|
-
if ((0, _treeUtils.compareArray)(expandItemValues, prevState.expandItemValues)) {
|
|
593
|
+
if ((0, _treeUtils.compareArray)(expandItemValues, prevState.expandItemValues) && (0, _isArray2.default)(expandItemValues)) {
|
|
594
594
|
this.unserializeLists({
|
|
595
595
|
expand: expandItemValues
|
|
596
596
|
});
|
|
@@ -607,7 +607,7 @@ function (_React$Component) {
|
|
|
607
607
|
expandItemValues = _this$state3.expandItemValues;
|
|
608
608
|
var uncheckableItemValues = this.props.uncheckableItemValues;
|
|
609
609
|
|
|
610
|
-
if ((0, _treeUtils.compareArray)(uncheckableItemValues, prevState.uncheckableItemValues)) {
|
|
610
|
+
if ((0, _treeUtils.compareArray)(uncheckableItemValues, prevState.uncheckableItemValues) && (0, _isArray2.default)(uncheckableItemValues)) {
|
|
611
611
|
this.flattenNodes(data);
|
|
612
612
|
this.unserializeLists({
|
|
613
613
|
check: selectedValues,
|
|
@@ -659,6 +659,7 @@ function (_React$Component) {
|
|
|
659
659
|
|
|
660
660
|
if ((0, _utils2.isEveryChildChecked)(node, this.nodes, this.props)) {
|
|
661
661
|
this.nodes[node.refKey].checkAll = true;
|
|
662
|
+
this.nodes[node.refKey].check = true;
|
|
662
663
|
return _constants.CHECK_STATE.CHECK;
|
|
663
664
|
}
|
|
664
665
|
|
|
@@ -878,7 +879,7 @@ function (_React$Component) {
|
|
|
878
879
|
});
|
|
879
880
|
}
|
|
880
881
|
/**
|
|
881
|
-
* 过滤选中的values中不包含 uncheckableItemValues 的那些值
|
|
882
|
+
* 过滤选中的 values 中不包含 uncheckableItemValues 的那些值
|
|
882
883
|
* @param {*} values
|
|
883
884
|
*/
|
|
884
885
|
;
|
|
@@ -1039,7 +1040,7 @@ function (_React$Component) {
|
|
|
1039
1040
|
};
|
|
1040
1041
|
|
|
1041
1042
|
_proto.toggleNode = function toggleNode(key, node, toggleValue) {
|
|
1042
|
-
// 如果该节点处于
|
|
1043
|
+
// 如果该节点处于 disabledCheckbox,则忽略该值
|
|
1043
1044
|
if (!node.uncheckable) {
|
|
1044
1045
|
this.nodes[node.refKey][key] = toggleValue;
|
|
1045
1046
|
}
|
package/lib/utils/treeUtils.js
CHANGED
|
@@ -185,7 +185,11 @@ function treeDeprecatedWarning(props, keys) {
|
|
|
185
185
|
|
|
186
186
|
|
|
187
187
|
function compareArray(a, b) {
|
|
188
|
-
|
|
188
|
+
if (!((0, _isArray2.default)(a) && (0, _isArray2.default)(b))) {
|
|
189
|
+
return a !== b;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return !(0, _shallowEqualArray.default)(a, b);
|
|
189
193
|
}
|
|
190
194
|
/**
|
|
191
195
|
* 获取 expandAll 的 value
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rsuite",
|
|
3
|
-
"version": "4.10.
|
|
3
|
+
"version": "4.10.2",
|
|
4
4
|
"description": "A suite of react components",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"classnames": ">=2.0.0",
|
|
58
58
|
"date-fns": "^1.30.1",
|
|
59
59
|
"dom-lib": "^1.2.1",
|
|
60
|
-
"element-resize-event": "^3.0.
|
|
60
|
+
"element-resize-event": "^3.0.6",
|
|
61
61
|
"lodash": "^4.17.11",
|
|
62
62
|
"prop-types": "^15.7.2",
|
|
63
63
|
"react-lifecycles-compat": "^3.0.4",
|
|
@@ -195,11 +195,14 @@ class CheckTreePicker extends React.Component<CheckTreePickerProps, CheckTreePic
|
|
|
195
195
|
nextState.value = value;
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
if (compareArray(expandItemValues, prevState.expandItemValues)) {
|
|
198
|
+
if (compareArray(expandItemValues, prevState.expandItemValues) && _.isArray(expandItemValues)) {
|
|
199
199
|
nextState.expandItemValues = expandItemValues;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
if (
|
|
202
|
+
if (
|
|
203
|
+
compareArray(uncheckableItemValues, prevState.uncheckableItemValues) &&
|
|
204
|
+
_.isArray(uncheckableItemValues)
|
|
205
|
+
) {
|
|
203
206
|
nextState.uncheckableItemValues = uncheckableItemValues;
|
|
204
207
|
}
|
|
205
208
|
|
|
@@ -258,7 +261,7 @@ class CheckTreePicker extends React.Component<CheckTreePickerProps, CheckTreePic
|
|
|
258
261
|
const { value } = this.props;
|
|
259
262
|
if (compareArray(value, prevState.value)) {
|
|
260
263
|
this.unserializeLists({
|
|
261
|
-
check: value,
|
|
264
|
+
check: value ?? [],
|
|
262
265
|
expand: expandItemValues
|
|
263
266
|
});
|
|
264
267
|
this.setState({
|
|
@@ -271,7 +274,7 @@ class CheckTreePicker extends React.Component<CheckTreePickerProps, CheckTreePic
|
|
|
271
274
|
|
|
272
275
|
updateExpandItemValuesChange(prevState: CheckTreePickerState) {
|
|
273
276
|
const { expandItemValues } = this.props;
|
|
274
|
-
if (compareArray(expandItemValues, prevState.expandItemValues)) {
|
|
277
|
+
if (compareArray(expandItemValues, prevState.expandItemValues) && _.isArray(expandItemValues)) {
|
|
275
278
|
this.unserializeLists({
|
|
276
279
|
expand: expandItemValues
|
|
277
280
|
});
|
|
@@ -284,7 +287,10 @@ class CheckTreePicker extends React.Component<CheckTreePickerProps, CheckTreePic
|
|
|
284
287
|
updateUncheckableItemValuesChange(prevState: CheckTreePickerState) {
|
|
285
288
|
const { data, selectedValues, expandItemValues } = this.state;
|
|
286
289
|
const { uncheckableItemValues } = this.props;
|
|
287
|
-
if (
|
|
290
|
+
if (
|
|
291
|
+
compareArray(uncheckableItemValues, prevState.uncheckableItemValues) &&
|
|
292
|
+
_.isArray(uncheckableItemValues)
|
|
293
|
+
) {
|
|
288
294
|
this.flattenNodes(data);
|
|
289
295
|
this.unserializeLists({
|
|
290
296
|
check: selectedValues,
|
|
@@ -343,6 +349,7 @@ class CheckTreePicker extends React.Component<CheckTreePickerProps, CheckTreePic
|
|
|
343
349
|
|
|
344
350
|
if (isEveryChildChecked(node, this.nodes, this.props)) {
|
|
345
351
|
this.nodes[node.refKey].checkAll = true;
|
|
352
|
+
this.nodes[node.refKey].check = true;
|
|
346
353
|
return CHECK_STATE.CHECK;
|
|
347
354
|
}
|
|
348
355
|
|
|
@@ -481,6 +488,7 @@ class CheckTreePicker extends React.Component<CheckTreePickerProps, CheckTreePic
|
|
|
481
488
|
const checkItems = [];
|
|
482
489
|
Object.keys(this.nodes).map((refKey: string) => {
|
|
483
490
|
const node = this.nodes[refKey];
|
|
491
|
+
|
|
484
492
|
if (selectedValues.some((value: any) => shallowEqual(node[valueKey], value))) {
|
|
485
493
|
checkItems.push(node);
|
|
486
494
|
}
|
|
@@ -531,7 +539,7 @@ class CheckTreePicker extends React.Component<CheckTreePickerProps, CheckTreePic
|
|
|
531
539
|
}
|
|
532
540
|
|
|
533
541
|
/**
|
|
534
|
-
* 过滤选中的values中不包含 uncheckableItemValues 的那些值
|
|
542
|
+
* 过滤选中的 values 中不包含 uncheckableItemValues 的那些值
|
|
535
543
|
* @param {*} values
|
|
536
544
|
*/
|
|
537
545
|
filterSelectedValues(values: any[]) {
|
|
@@ -743,7 +751,7 @@ class CheckTreePicker extends React.Component<CheckTreePickerProps, CheckTreePic
|
|
|
743
751
|
}
|
|
744
752
|
|
|
745
753
|
toggleNode(key: string, node: Node, toggleValue: boolean) {
|
|
746
|
-
// 如果该节点处于
|
|
754
|
+
// 如果该节点处于 disabledCheckbox,则忽略该值
|
|
747
755
|
if (!node.uncheckable) {
|
|
748
756
|
this.nodes[node.refKey][key] = toggleValue;
|
|
749
757
|
}
|
|
@@ -4,10 +4,23 @@ import Enzyme, { mount } from 'enzyme';
|
|
|
4
4
|
import Adapter from 'enzyme-adapter-react-16';
|
|
5
5
|
import { getDOMNode, getInstance } from '@test/testUtils';
|
|
6
6
|
import CheckTreePicker from '../CheckTreePicker';
|
|
7
|
-
import { findDOMNode } from 'react-dom';
|
|
7
|
+
import ReactDOM, { findDOMNode } from 'react-dom';
|
|
8
|
+
import { assert } from 'chai';
|
|
8
9
|
|
|
9
10
|
Enzyme.configure({ adapter: new Adapter() });
|
|
10
11
|
|
|
12
|
+
let container;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
container = document.createElement('div');
|
|
16
|
+
document.body.appendChild(container);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
document.body.removeChild(container);
|
|
21
|
+
container = null;
|
|
22
|
+
});
|
|
23
|
+
|
|
11
24
|
const data = [
|
|
12
25
|
{
|
|
13
26
|
label: 'Master',
|
|
@@ -298,6 +311,66 @@ describe('CheckTreePicker', () => {
|
|
|
298
311
|
instance.unmount();
|
|
299
312
|
});
|
|
300
313
|
|
|
314
|
+
it('Should return 2 values', done => {
|
|
315
|
+
const customData = [
|
|
316
|
+
{
|
|
317
|
+
value: '1',
|
|
318
|
+
label: '1',
|
|
319
|
+
children: [
|
|
320
|
+
{
|
|
321
|
+
value: '1-1',
|
|
322
|
+
label: '1-1'
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
value: '1-2',
|
|
326
|
+
label: '1-2'
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
value: '1-3',
|
|
330
|
+
label: '1-3'
|
|
331
|
+
}
|
|
332
|
+
]
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
value: '2',
|
|
336
|
+
label: '2',
|
|
337
|
+
children: [
|
|
338
|
+
{
|
|
339
|
+
value: '2-1',
|
|
340
|
+
label: '2-1'
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
value: '2-2',
|
|
344
|
+
label: '2-2'
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
value: '2-3',
|
|
348
|
+
label: '2-3'
|
|
349
|
+
}
|
|
350
|
+
]
|
|
351
|
+
}
|
|
352
|
+
];
|
|
353
|
+
|
|
354
|
+
const doneOp = values => {
|
|
355
|
+
if (values.length === 2) {
|
|
356
|
+
done();
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
const instance = getDOMNode(
|
|
360
|
+
<CheckTreePicker
|
|
361
|
+
data={customData}
|
|
362
|
+
inline
|
|
363
|
+
value={['1-1', '1-2', '1-3']}
|
|
364
|
+
cascade
|
|
365
|
+
defaultExpandAll
|
|
366
|
+
onChange={doneOp}
|
|
367
|
+
/>
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
assert.equal(instance.querySelectorAll('.rs-checkbox-checked').length, 4);
|
|
371
|
+
ReactTestUtils.Simulate.change(instance.querySelectorAll('.rs-check-tree-node input')[5]);
|
|
372
|
+
});
|
|
373
|
+
|
|
301
374
|
it('Should render empty tree when searchKeyword is `name`', () => {
|
|
302
375
|
const instance = mount(<CheckTreePicker data={data} inline searchKeyword="name" />);
|
|
303
376
|
assert.equal(instance.find('.rs-check-tree-node').length, 0);
|
|
@@ -384,4 +457,114 @@ describe('CheckTreePicker', () => {
|
|
|
384
457
|
assert.equal(instance2.querySelector('.rs-picker-toggle-placeholder').innerText, 'Select');
|
|
385
458
|
assert.equal(instance3.querySelector('.rs-picker-toggle-placeholder').innerText, 'Select');
|
|
386
459
|
});
|
|
460
|
+
|
|
461
|
+
it('Should controlled by value', () => {
|
|
462
|
+
const TestApp = React.forwardRef((props, ref) => {
|
|
463
|
+
const [value, setValue] = React.useState();
|
|
464
|
+
const pickerRef = React.useRef();
|
|
465
|
+
React.useImperativeHandle(ref, () => ({
|
|
466
|
+
picker: pickerRef.current,
|
|
467
|
+
setValue
|
|
468
|
+
}));
|
|
469
|
+
|
|
470
|
+
return <CheckTreePicker data={data} ref={pickerRef} value={value} defaultExpandAll open />;
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
TestApp.displayName = 'TestCheckTreePicker';
|
|
474
|
+
|
|
475
|
+
const ref = React.createRef();
|
|
476
|
+
ReactTestUtils.act(() => {
|
|
477
|
+
ReactDOM.render(<TestApp ref={ref} />, container);
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
assert.equal(
|
|
481
|
+
ref.current.picker.treeViewRef.current.querySelectorAll('.rs-checkbox-checked').length,
|
|
482
|
+
0
|
|
483
|
+
);
|
|
484
|
+
|
|
485
|
+
ReactTestUtils.act(() => {
|
|
486
|
+
ref.current.setValue(['Master']);
|
|
487
|
+
});
|
|
488
|
+
assert.equal(
|
|
489
|
+
ref.current.picker.treeViewRef.current.querySelectorAll('.rs-checkbox-checked').length,
|
|
490
|
+
4
|
|
491
|
+
);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it('Should controlled by expandItemValues', () => {
|
|
495
|
+
const TestApp = React.forwardRef((props, ref) => {
|
|
496
|
+
const [expandItemValues, setExpandItemValues] = React.useState();
|
|
497
|
+
const pickerRef = React.useRef();
|
|
498
|
+
React.useImperativeHandle(ref, () => ({
|
|
499
|
+
picker: pickerRef.current,
|
|
500
|
+
setExpandItemValues
|
|
501
|
+
}));
|
|
502
|
+
|
|
503
|
+
return (
|
|
504
|
+
<CheckTreePicker data={data} ref={pickerRef} expandItemValues={expandItemValues} open />
|
|
505
|
+
);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
TestApp.displayName = 'TestCheckTreePicker';
|
|
509
|
+
|
|
510
|
+
const ref = React.createRef();
|
|
511
|
+
ReactTestUtils.act(() => {
|
|
512
|
+
ReactDOM.render(<TestApp ref={ref} />, container);
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
assert.equal(
|
|
516
|
+
ref.current.picker.treeViewRef.current.querySelectorAll('.rs-check-tree-node-expanded')
|
|
517
|
+
.length,
|
|
518
|
+
0
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
ReactTestUtils.act(() => {
|
|
522
|
+
ref.current.setExpandItemValues(['Master']);
|
|
523
|
+
});
|
|
524
|
+
assert.equal(
|
|
525
|
+
ref.current.picker.treeViewRef.current.querySelectorAll('.rs-check-tree-node-expanded')
|
|
526
|
+
.length,
|
|
527
|
+
1
|
|
528
|
+
);
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it('Should controlled by uncheckableItemValues', () => {
|
|
532
|
+
const TestApp = React.forwardRef((props, ref) => {
|
|
533
|
+
const [uncheckableItemValues, setUncheckableItemValues] = React.useState();
|
|
534
|
+
const pickerRef = React.useRef();
|
|
535
|
+
React.useImperativeHandle(ref, () => ({
|
|
536
|
+
picker: pickerRef.current,
|
|
537
|
+
setUncheckableItemValues
|
|
538
|
+
}));
|
|
539
|
+
|
|
540
|
+
return (
|
|
541
|
+
<CheckTreePicker
|
|
542
|
+
data={data}
|
|
543
|
+
ref={pickerRef}
|
|
544
|
+
uncheckableItemValues={uncheckableItemValues}
|
|
545
|
+
open
|
|
546
|
+
/>
|
|
547
|
+
);
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
TestApp.displayName = 'TestCheckTreePicker';
|
|
551
|
+
|
|
552
|
+
const ref = React.createRef();
|
|
553
|
+
ReactTestUtils.act(() => {
|
|
554
|
+
ReactDOM.render(<TestApp ref={ref} />, container);
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
assert.equal(
|
|
558
|
+
ref.current.picker.treeViewRef.current.querySelectorAll('.rs-checkbox-inner').length,
|
|
559
|
+
5
|
|
560
|
+
);
|
|
561
|
+
|
|
562
|
+
ReactTestUtils.act(() => {
|
|
563
|
+
ref.current.setUncheckableItemValues(['Master']);
|
|
564
|
+
});
|
|
565
|
+
assert.equal(
|
|
566
|
+
ref.current.picker.treeViewRef.current.querySelectorAll('.rs-checkbox-inner').length,
|
|
567
|
+
4
|
|
568
|
+
);
|
|
569
|
+
});
|
|
387
570
|
});
|
|
@@ -2,13 +2,22 @@ import React from 'react';
|
|
|
2
2
|
import ReactTestUtils from 'react-dom/test-utils';
|
|
3
3
|
import Enzyme, { mount } from 'enzyme';
|
|
4
4
|
import Adapter from 'enzyme-adapter-react-16';
|
|
5
|
-
import { findDOMNode } from 'react-dom';
|
|
5
|
+
import ReactDOM, { findDOMNode } from 'react-dom';
|
|
6
6
|
import { getDOMNode, getInstance } from '@test/testUtils';
|
|
7
7
|
import TreePicker from '../TreePicker';
|
|
8
8
|
|
|
9
9
|
Enzyme.configure({ adapter: new Adapter() });
|
|
10
|
+
let container;
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
container = document.createElement('div');
|
|
14
|
+
document.body.appendChild(container);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
document.body.removeChild(container);
|
|
19
|
+
container = null;
|
|
20
|
+
});
|
|
12
21
|
|
|
13
22
|
const data = [
|
|
14
23
|
{
|
|
@@ -157,7 +166,7 @@ describe('TreePicker', () => {
|
|
|
157
166
|
});
|
|
158
167
|
|
|
159
168
|
it('Should call `onChange` callback', done => {
|
|
160
|
-
const doneOp =
|
|
169
|
+
const doneOp = () => {
|
|
161
170
|
done();
|
|
162
171
|
};
|
|
163
172
|
const instance = getDOMNode(<TreePicker inline onChange={doneOp} data={data} />);
|
|
@@ -243,7 +252,7 @@ describe('TreePicker', () => {
|
|
|
243
252
|
});
|
|
244
253
|
|
|
245
254
|
it('Should focus item by keyCode=13 ', done => {
|
|
246
|
-
const doneOp =
|
|
255
|
+
const doneOp = () => {
|
|
247
256
|
done();
|
|
248
257
|
};
|
|
249
258
|
const instance = mount(<TreePicker data={data} onChange={doneOp} inline defaultExpandAll />);
|
|
@@ -271,8 +280,6 @@ describe('TreePicker', () => {
|
|
|
271
280
|
});
|
|
272
281
|
|
|
273
282
|
it('Should load data async', () => {
|
|
274
|
-
let activeNode = null;
|
|
275
|
-
let layer = 0;
|
|
276
283
|
const data = [
|
|
277
284
|
{
|
|
278
285
|
label: 'Master',
|
|
@@ -293,8 +300,6 @@ describe('TreePicker', () => {
|
|
|
293
300
|
|
|
294
301
|
let newData = [];
|
|
295
302
|
const mockOnExpand = (node, l, concat) => {
|
|
296
|
-
activeNode = node;
|
|
297
|
-
layer = l;
|
|
298
303
|
newData = concat(data, children);
|
|
299
304
|
};
|
|
300
305
|
|
|
@@ -391,13 +396,36 @@ describe('TreePicker', () => {
|
|
|
391
396
|
assert.ok(list[0].innerText, 'Louisa');
|
|
392
397
|
});
|
|
393
398
|
|
|
394
|
-
it('Should
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
|
|
399
|
+
it('Should controlled by expandItemValues', () => {
|
|
400
|
+
const TestApp = React.forwardRef((props, ref) => {
|
|
401
|
+
const [expandItemValues, setExpandItemValues] = React.useState();
|
|
402
|
+
const pickerRef = React.useRef();
|
|
403
|
+
React.useImperativeHandle(ref, () => ({
|
|
404
|
+
picker: pickerRef.current,
|
|
405
|
+
setExpandItemValues
|
|
406
|
+
}));
|
|
407
|
+
|
|
408
|
+
return <TreePicker data={data} ref={pickerRef} expandItemValues={expandItemValues} open />;
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
TestApp.displayName = 'TestCheckTreePicker';
|
|
412
|
+
|
|
413
|
+
const ref = React.createRef();
|
|
414
|
+
ReactTestUtils.act(() => {
|
|
415
|
+
ReactDOM.render(<TestApp ref={ref} />, container);
|
|
416
|
+
});
|
|
398
417
|
|
|
399
|
-
assert.equal(
|
|
400
|
-
|
|
401
|
-
|
|
418
|
+
assert.equal(
|
|
419
|
+
ref.current.picker.treeViewRef.current.querySelectorAll('.rs-tree-node-expanded').length,
|
|
420
|
+
0
|
|
421
|
+
);
|
|
422
|
+
|
|
423
|
+
ReactTestUtils.act(() => {
|
|
424
|
+
ref.current.setExpandItemValues(['Master']);
|
|
425
|
+
});
|
|
426
|
+
assert.equal(
|
|
427
|
+
ref.current.picker.treeViewRef.current.querySelectorAll('.rs-tree-node-expanded').length,
|
|
428
|
+
1
|
|
429
|
+
);
|
|
402
430
|
});
|
|
403
431
|
});
|
package/src/utils/treeUtils.ts
CHANGED
|
@@ -123,7 +123,10 @@ export function treeDeprecatedWarning(
|
|
|
123
123
|
* @param b
|
|
124
124
|
*/
|
|
125
125
|
export function compareArray(a: any[], b: any[]) {
|
|
126
|
-
|
|
126
|
+
if (!(_.isArray(a) && _.isArray(b))) {
|
|
127
|
+
return a !== b;
|
|
128
|
+
}
|
|
129
|
+
return !shallowEqualArray(a, b);
|
|
127
130
|
}
|
|
128
131
|
|
|
129
132
|
/**
|