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

feat: add keywords prop to the item component #158

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

itaikeren
Copy link
Contributor

This PR adds the keywords prop to the Item component.

Closes #146

@vercel
Copy link

vercel bot commented Jul 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cmdk-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 18, 2023 9:19am

@TheMikeyRoss
Copy link

half a year later

@lucsmachado
Copy link

While this is pending review, here's a workaround I'm using:

<Command
  filter={(value, search) => {
    const extendValue = `${value} ${getKeywords(value).join(' ')}`;
    if (extendValue.includes(search)) return 1
    return 0
  }}
/>

Then you can define getKeywords(value: string): string[] as desired. Example for my usecase:

const getKeywords = (value: string) => {
  const keywords: string[] = [];
  const foundItem = items.find(
    // `toLowerCase()` is needed because `value` is normalized as lowercase (per the documentation)
    (item) => item.name.toLowerCase() === value,
  );
  if (foundItem) {
    keywords.push(foundItem.cpf);
  }
  return keywords;
};

@pacocoursey pacocoursey merged commit eb404c0 into pacocoursey:main Jan 30, 2024
@petrkrejcik
Copy link

@pacocoursey
FYI this feature isn't released.
The release v0.2.1 was made right before merging this PR.

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.

Custom keywords in filter
5 participants