Skip to content

Commit

Permalink
fix: correct update option's label when update value (equal label) in…
Browse files Browse the repository at this point in the history
… options (#580)
  • Loading branch information
wangao authored Dec 24, 2020
1 parent d393076 commit ff5eaeb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hooks/useCacheDisplayValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function useCacheDisplayValue(

const resultValues = values.map(item => {
const cacheLabel = valueLabels.get(item.value);
if (item.value === item.label && cacheLabel) {
if (item.isCacheable && cacheLabel) {
return {
...item,
label: cacheLabel,
Expand Down
1 change: 1 addition & 0 deletions src/interface/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface LabelValueType {
key?: Key;
value?: RawValueType;
label?: React.ReactNode;
isCacheable?: Boolean;
}
export type DefaultValueType = RawValueType | RawValueType[] | LabelValueType | LabelValueType[];

Expand Down
1 change: 1 addition & 0 deletions src/utils/valueUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export const getLabeledValue: GetLabeledValue<FlattenOptionData[]> = (
result.label = item[optionLabelProp];
} else {
result.label = value;
result.isCacheable = true;
}

// Used for motion control
Expand Down
3 changes: 3 additions & 0 deletions tests/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,9 @@ describe('Select.Basic', () => {

wrapper.setProps({ options: [] });
expect(findSelection(wrapper).text()).toEqual('Bamboo');

wrapper.setProps({ options: [{ value: 903, label: 903 }] });
expect(findSelection(wrapper).text()).toEqual('903');
});

// https://github.com/ant-design/ant-design/issues/24747
Expand Down

1 comment on commit ff5eaeb

@vercel
Copy link

@vercel vercel bot commented on ff5eaeb Dec 24, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.