Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/utils/commonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,25 @@ export function toInnerValue(
): [RawValueType[], Map<RawValueType, LabelValueType>] {
const valueMap = new Map<RawValueType, LabelValueType>();

if (value === undefined || (value === '' && combobox)) {
if (
value === undefined ||
(value === '' && combobox)
) {
return [[], valueMap];
}

const values = Array.isArray(value) ? value : [value];
let rawValues = values as RawValueType[];

if (labelInValue) {
rawValues = (values as LabelValueType[]).map((itemValue: LabelValueType) => {
const { key, value: val } = itemValue;
const finalVal = val !== undefined ? val : key;
valueMap.set(finalVal, itemValue);
return finalVal;
});
rawValues = (values as LabelValueType[])
.filter(item => !!item)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加个用例?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加过啦 ~~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~ 这个能合么

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value 为 0 时,也被 filter 了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dolov 再来个 PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value 为 0 时,也被 filter 了

labelInValue 模式下,需要支持这种非法数据格式么

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有 ts 定义,先不加了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用js的项目呢?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂😂😂 对,忘了 还有 js

.map((itemValue: LabelValueType) => {
const { key, value: val } = itemValue;
const finalVal = val !== undefined ? val : key;
valueMap.set(finalVal, itemValue);
return finalVal;
});
}

return [rawValues, valueMap];
Expand Down
4 changes: 4 additions & 0 deletions tests/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,10 @@ describe('Select.Basic', () => {
mount(<Select options={null} />);
});

it('not crash when labelInValue and value is null', () => {
mount(<Select labelInValue value={null} />);
});

it('not open when `notFoundCount` is empty & no data', () => {
const wrapper = mount(<Select options={null} notFoundContent={null} open showSearch />);
expect(wrapper.find('SelectTrigger').props().visible).toBeFalsy();
Expand Down