Skip to content

Commit deb6d76

Browse files
authored
fix: improve to not treat as a valid option when the value is null. (#564)
Co-authored-by: ​ <​>
1 parent 23606d8 commit deb6d76

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/TreeSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
390390

391391
// =========================== Values ===========================
392392
const rawMixedLabeledValues = React.useMemo(
393-
() => toLabeledValues(internalValue),
393+
() => toLabeledValues(internalValue === null ? [] : internalValue),
394394
[toLabeledValues, internalValue],
395395
);
396396

tests/Select.multiple.spec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,42 @@ describe('TreeSelect.multiple', () => {
310310
).map(ele => ele.textContent);
311311
expect(values).toEqual(['child1', 'child2', 'parent']);
312312
});
313+
314+
// https://github.com/ant-design/ant-design/issues/50578#issuecomment-2312130715
315+
it('should not omit value when value is null', () => {
316+
const { container } = render(
317+
<TreeSelect
318+
value={null}
319+
multiple
320+
placeholder="Fake placeholder"
321+
treeData={[
322+
{
323+
label: 'parent',
324+
value: 'parent',
325+
children: [
326+
{
327+
label: 'child1',
328+
value: 'child1',
329+
},
330+
{
331+
label: 'child2',
332+
value: 'child2',
333+
},
334+
],
335+
},
336+
]}
337+
/>,
338+
);
339+
340+
const values = Array.from(
341+
container.querySelectorAll('.rc-tree-select-selection-item-content'),
342+
); //.map(ele => ele.textContent);
343+
344+
expect(values).toHaveLength(0);
345+
346+
const placeholder = container.querySelector('[class$=placeholder]');
347+
expect(placeholder).toBeTruthy();
348+
expect(placeholder.textContent).toBe('Fake placeholder');
349+
});
350+
313351
});

0 commit comments

Comments
 (0)