Skip to content

fix(select): select component not taking keys according to the corresponding value when passing fieldNames #8247

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions components/vc-select/utils/valueUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import type { BaseOptionType, DefaultOptionType, RawValueType, FieldNames } from
import { warning } from '../../vc-util/warning';
import type { FlattenOptionData } from '../interface';

function getKey(data: BaseOptionType, index: number) {
function getKey(data: BaseOptionType, index: number, fieldNames?: FieldNames) {
const { key } = data;
let value: RawValueType;

if ('value' in data) {
if (fieldNames && fieldNames.value && data[fieldNames.value] !== undefined) {
({ [fieldNames.value]: value } = data);
} else if ('value' in data) {
({ value } = data);
}

Expand Down Expand Up @@ -54,7 +56,7 @@ export function flattenOptions<OptionType extends BaseOptionType = DefaultOption
const value = data[fieldValue];
// Option
flattenList.push({
key: getKey(data, flattenList.length),
key: getKey(data, flattenList.length, fieldNames),
groupOption: isGroupOption,
data,
label,
Expand All @@ -67,7 +69,7 @@ export function flattenOptions<OptionType extends BaseOptionType = DefaultOption
}
// Option Group
flattenList.push({
key: getKey(data, flattenList.length),
key: getKey(data, flattenList.length, fieldNames),
group: true,
data,
label: grpLabel,
Expand Down