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

[Bug]: Why ComboBox is not seraching with labels? #758

Open
2 tasks
meghraj-suthar opened this issue Sep 10, 2024 · 1 comment
Open
2 tasks

[Bug]: Why ComboBox is not seraching with labels? #758

meghraj-suthar opened this issue Sep 10, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@meghraj-suthar
Copy link

Reproduction

It can be easily produced on the main site as well by changing the value field from available combox options: https://www.shadcn-vue.com/docs/components/combobox.html Just change value to 1,2,3,4,5,6 and then search for a label

Describe the bug

As a user, they'll always search for the visible item name in the combobox. Where value could be anything like a list of users and their ids as value. How will a user search for labels here?

Screenshot 2024-09-11 at 2 10 01 AM Screenshot 2024-09-11 at 2 09 56 AM

System Info

System:
    OS: macOS 14.6.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 785.78 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.12.2 - ~/.volta/tools/image/node/20.12.2/bin/node
    Yarn: 1.22.19 - ~/.volta/tools/image/yarn/4.2.1/bin/yarn
    npm: 10.5.0 - ~/.volta/tools/image/node/20.12.2/bin/npm
    Watchman: HEAD-a373c76 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 128.0.6613.120
    Safari: 17.6
  npmPackages:
    @vueuse/core: ^11.0.3 => 11.0.3 
    radix-vue: ^1.9.5 => 1.9.5 
    vue: ^3.4.29 => 3.5.3

Contributes

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests
@meghraj-suthar meghraj-suthar added the bug Something isn't working label Sep 10, 2024
@Dam998
Copy link

Dam998 commented Oct 24, 2024

You can do something like this:

<script>

...

function filterFunction(list: string[], searchTerm: string) {
  return list.filter((langLabel) => {
    if (langLabel.toLowerCase().includes(searchTerm.toLowerCase())) {
      return true;
    }

    const lang = languages.find((lang) => lang.label === langLabel);
    return lang?.value.toLowerCase().includes(searchTerm.toLowerCase());
  });
}
</script>

<template>

...
<PopoverContent class="w-[200px] p-0">
            <Command :filter-function="filterFunction">
...

</template>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants