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

Conversation

junyangfan
Copy link

@junyangfan junyangfan commented Jun 26, 2025

When clicking on the dropdown menu to select and scroll.

Select1 is incorrect because the key was not generated based on the value in fieldNames,And the keys in the options object array hit duplicate value values. while Select2 is correct because the value itself generates the key as a unique value.

<template>
  Select1: An error occurred when clicking on the dropdown menu, selecting and scrolling
  <a-select
    style="width: 200px"
    v-model:value="state.id1"
    :fieldNames="{ label: 'value', value: 'code' }"
    :options="arr1"
  />
  Select2: correct
  <a-select
    style="width: 200px"
    v-model:value="state.id2"
    :options="arr2"
  />
</template>
<script setup lang="ts">
import { ref } from "vue";

const state = ref({
  id1: "",
  id2: "",
});

// Hit value with duplicate values
const arr1 = generateObjectsWithRepeat(['code', 'value'], 40, 'value', 'X', 10);

const arr2 = generateObjectsWithRepeat(['value', 'label'], 40, 'label', 'X', 10);

function generateObjectsWithRepeat(keys, count, repeatKey, repeatValue, repeatTimes) {
  const arr = [];
  for (let i = 0; i < count; i++) {
    const obj = {};
    keys.forEach((key, idx) => {
      obj[key] = `${key}_${i+1}`;
    });
    arr.push(obj);
  }
  let inserted = 0;
  while (inserted < repeatTimes) {
    const idx = Math.floor(Math.random() * count);
    if (arr[idx][repeatKey] !== repeatValue) {
      arr[idx][repeatKey] = repeatValue;
      inserted++;
    }
  }
  return arr;
}
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant