Skip to content

Commit

Permalink
fix: improve to not treat as a valid option when the value is null. (#…
Browse files Browse the repository at this point in the history
…564)

Co-authored-by: ​ <​>
  • Loading branch information
Wxh16144 committed Aug 28, 2024
1 parent 23606d8 commit deb6d76
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/TreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)

// =========================== Values ===========================
const rawMixedLabeledValues = React.useMemo(
() => toLabeledValues(internalValue),
() => toLabeledValues(internalValue === null ? [] : internalValue),
[toLabeledValues, internalValue],
);

Expand Down
38 changes: 38 additions & 0 deletions tests/Select.multiple.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,42 @@ describe('TreeSelect.multiple', () => {
).map(ele => ele.textContent);
expect(values).toEqual(['child1', 'child2', 'parent']);
});

// https://github.com/ant-design/ant-design/issues/50578#issuecomment-2312130715
it('should not omit value when value is null', () => {
const { container } = render(
<TreeSelect
value={null}
multiple
placeholder="Fake placeholder"
treeData={[
{
label: 'parent',
value: 'parent',
children: [
{
label: 'child1',
value: 'child1',
},
{
label: 'child2',
value: 'child2',
},
],
},
]}
/>,
);

const values = Array.from(
container.querySelectorAll('.rc-tree-select-selection-item-content'),
); //.map(ele => ele.textContent);

expect(values).toHaveLength(0);

const placeholder = container.querySelector('[class$=placeholder]');
expect(placeholder).toBeTruthy();
expect(placeholder.textContent).toBe('Fake placeholder');
});

});

0 comments on commit deb6d76

Please sign in to comment.