Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct update option's label when update value (equal label) in options #580

Merged
merged 1 commit into from
Dec 24, 2020
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
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