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

Merged
merged 1 commit into from
Aug 27, 2025

Conversation

junyangfan
Copy link
Contributor

@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>

Copy link

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the Stale label Aug 26, 2025
@junyangfan
Copy link
Contributor Author

Keep this PR open.

@junyangfan
Copy link
Contributor Author

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

Keep this PR open.

@github-actions github-actions bot removed the Stale label Aug 27, 2025
@tangjinzhou tangjinzhou merged commit 57ea8a6 into vueComponent:main Aug 27, 2025
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.

2 participants