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

[Feature]: Make custom filter-function for CommandDialog Component #284

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

romanhrynevych
Copy link
Collaborator

Main reason of this PR is to close this issue #158 , but think that it will be helpful to add new Demo with @vueuse/useFuse filtering

Have some errors with creating new Demo, @sadeghbarati need help from you because previously I never worked with this type of projects 🙂

image

Link to Demo: www/src/lib/registry/default/example/CommandDialogUseFuseDemo.vue

Styling and other will fixed later, need to understand how to add a new Demo code 😁

@sadeghbarati
Copy link
Collaborator

I'm on it, will explain after commit

@romanhrynevych
Copy link
Collaborator Author

Thanks!

@sadeghbarati
Copy link
Collaborator

sadeghbarati commented Jan 17, 2024

When you have create demos you have two options

  1. update apps/www/__registry__/index.ts manually (add demos)

  2. you can run pnpm build:registry when you created demos in both styles

@romanhrynevych
Copy link
Collaborator Author

Great, thanks for explanation! ❤️

Need some help with this issue, because it contains many issues inside 😁 Now I added custom filter-function props to CommandDialog.vue component, but there are some other suggestion and I don't know if we need to fix them)

  1. In Issue [Feature]: Make it possible to use CommandInput with our own filtering method #158 you can see example with Algolia (API Fetch) CommandDialog, but there is some problems with dynamically change CommandItems inside CommandList, don't think that after change keyboard navigation will work at all 🙂
  2. There is some bug with useFuse too, if I add custom filter that will return output with shuffled order, keyboard navigation don't work properly, for fix I added shouldSort: false to useFuse.options.fuseOptions, but think that this must be fixed too

So one bug that need to be fixed now, dynamic change of CommandItem (insert, delete) that will toggle keyboard navigation logic to refresh. I'm not familiar with radix-vue on this level, maybe someone can help here.

I will try to fix this, need some help / time 🙂

@sadeghbarati
Copy link
Collaborator

sadeghbarati commented Jan 17, 2024

No need to rush 👍

There is also the same pkg for Vue called vue-command-palette which uses Fuse, you can take a look at it and see how it handles the search/sort/filtering

@sadeghbarati
Copy link
Collaborator

sadeghbarati commented Jan 17, 2024

@zernonia can we remove these aggressive warnings for a11y?

Other shadcns seem not to have these logs

Image of logs

image


Also, there is something wrong with CommandDialog which not showing DialogOverlay

https://stackblitz.com/edit/5h3b5u?file=src%2FApp.vue

@romanhrynevych romanhrynevych changed the title Feat[Command-Dialog]: Make custom filter-function for CommandDialog Component, extend Demos with CommandDialoguseFuse example [Feature]: Make custom filter-function for CommandDialog Component Jan 17, 2024
@maelp
Copy link

maelp commented Feb 8, 2024

Will this be merged?

This is how I'm solving it in CommandDialog for now

const props = defineProps<
  DialogRootProps & {
    filterFunction?: (val: Array<string | any>, term: string) => Array<any>;
  }
>();
const emits = defineEmits<DialogRootEmits>();

const forwarded = useForwardPropsEmits(props, emits);
const forwardedExceptFilterFunction = computed(() => {
  const { filterFunction: _, ...rest } = forwarded.value;
  return rest;
});

</script>

<template>
<Dialog v-bind="forwarded">
<DialogContent class="overflow-hidden p-0 shadow-lg">
<Command class="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
<Command :filter-function="props.filterFunction" class="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romanhrynevych can you check this line, it has TypeScript error

@maelp
Copy link

maelp commented Mar 1, 2024

if it can help, for me when I do Algolia search I do the following:

  • I bind the CommandDialog update:input to a method which triggers a query to algolia and get the results in a list
  • I show the list (without filering, eg filtering-function = (list, term) => list

so each time I type, I let Algolia do the "filtering" in the backend and return the result, and I display them "without filtering" (from CommandDialog) so that the users sees exactly the results of algolia

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.

None yet

3 participants