Skip to content

Commit 121c6d0

Browse files
committed
fix: rename and add test case with treeNode data
1 parent a07610e commit 121c6d0

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/TreeSelect.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
415415
const triggerChange = useRefFunc(
416416
(
417417
newRawValues: SafeKey[],
418-
extra: { triggerValue?: SafeKey; selected?: boolean; option?: DefaultOptionType },
418+
extra: { triggerValue?: SafeKey; selected?: boolean; nodes?: DefaultOptionType },
419419
source: SelectSource,
420420
) => {
421421
const labeledValues = convert2LabelValues(newRawValues);
@@ -461,7 +461,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
461461
// [Legacy] Always return as array contains label & value
462462
preValue: rawLabeledValues,
463463
triggerValue,
464-
option: extra.option,
464+
option: extra.nodes,
465465
} as ChangeEventExtra & { option?: DefaultOptionType };
466466

467467
// [Legacy] Fill legacy data if user query.
@@ -513,7 +513,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
513513
// Single mode always set value
514514
triggerChange(
515515
[selectedValue],
516-
{ selected: true, triggerValue: selectedValue, option: node as DefaultOptionType },
516+
{ selected: true, triggerValue: selectedValue, nodes: node as DefaultOptionType },
517517
'option',
518518
);
519519
} else {
@@ -547,7 +547,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
547547
}
548548
triggerChange(
549549
newRawValues,
550-
{ selected, triggerValue: selectedValue, option: node as DefaultOptionType },
550+
{ selected, triggerValue: selectedValue, nodes: node as DefaultOptionType },
551551
source || 'option',
552552
);
553553
}

tests/Select.props.spec.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,24 @@ describe('TreeSelect.props', () => {
310310
});
311311

312312
describe('showCheckedStrategy', () => {
313+
const treeData = {
314+
key: 'key 0',
315+
title: 'Title 0',
316+
value: 'Value 0',
317+
children: [
318+
{
319+
key: 'key 0-0',
320+
title: 'Title 0-0',
321+
value: 'Value 0-0',
322+
},
323+
{
324+
key: 'key 0-1',
325+
title: 'Title 0-1',
326+
value: 'Value 0-1',
327+
},
328+
],
329+
};
330+
313331
const testList = [
314332
{
315333
strategy: SHOW_ALL,
@@ -324,7 +342,7 @@ describe('TreeSelect.props', () => {
324342
}),
325343
],
326344
checked: true,
327-
option: expect.anything(),
345+
option: expect.objectContaining(treeData),
328346
preValue: [],
329347
triggerNode: expect.anything(),
330348
triggerValue: 'Value 0',
@@ -343,7 +361,7 @@ describe('TreeSelect.props', () => {
343361
}),
344362
],
345363
checked: true,
346-
option: expect.anything(),
364+
option: expect.objectContaining(treeData),
347365
preValue: [],
348366
triggerNode: expect.anything(),
349367
triggerValue: 'Value 0',
@@ -362,7 +380,7 @@ describe('TreeSelect.props', () => {
362380
}),
363381
],
364382
checked: true,
365-
option: expect.anything(),
383+
option: expect.objectContaining(treeData),
366384
preValue: [],
367385
triggerNode: expect.anything(),
368386
triggerValue: 'Value 0',

0 commit comments

Comments
 (0)