Skip to content

Commit ff5eaeb

Browse files
author
wangao
authored
fix: correct update option's label when update value (equal label) in options (#580)
1 parent d393076 commit ff5eaeb

File tree

4 files changed

+6
-1
lines changed

4 files changed

+6
-1
lines changed

src/hooks/useCacheDisplayValue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function useCacheDisplayValue(
1717

1818
const resultValues = values.map(item => {
1919
const cacheLabel = valueLabels.get(item.value);
20-
if (item.value === item.label && cacheLabel) {
20+
if (item.isCacheable && cacheLabel) {
2121
return {
2222
...item,
2323
label: cacheLabel,

src/interface/generator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface LabelValueType {
1313
key?: Key;
1414
value?: RawValueType;
1515
label?: React.ReactNode;
16+
isCacheable?: Boolean;
1617
}
1718
export type DefaultValueType = RawValueType | RawValueType[] | LabelValueType | LabelValueType[];
1819

src/utils/valueUtil.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export const getLabeledValue: GetLabeledValue<FlattenOptionData[]> = (
153153
result.label = item[optionLabelProp];
154154
} else {
155155
result.label = value;
156+
result.isCacheable = true;
156157
}
157158

158159
// Used for motion control

tests/Select.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,9 @@ describe('Select.Basic', () => {
16121612

16131613
wrapper.setProps({ options: [] });
16141614
expect(findSelection(wrapper).text()).toEqual('Bamboo');
1615+
1616+
wrapper.setProps({ options: [{ value: 903, label: 903 }] });
1617+
expect(findSelection(wrapper).text()).toEqual('903');
16151618
});
16161619

16171620
// https://github.com/ant-design/ant-design/issues/24747

0 commit comments

Comments
 (0)