-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
[question] How to change the command items on the fly? #36
Comments
There is something really strange with the Command.Input. The code bellow only works with common Input. and breakes with Command.Input <script lang="ts">
import * as Command from "$lib/components/ui/command";
import { Input } from "$lib/components/ui/input";
import { filterByQuery, runCommand } from "$lib/utils";
import pdms from "$lib/assets/pdm.json";
let open = true;
let query = "";
let selected = "";
$: filtered = filterByQuery(pdms, query)?.slice(0, 10);
$: console.log(filtered);
$: open = query.length > 0;
</script>
<Command.Root>
<Input
bind:value={query}
placeholder="Query..."
class = "w-72"
/>
{#if open}
<Command.List class="z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none">
<Command.Empty> Não encontrado. </Command.Empty>
{#each filtered as pdm}
<Command.Item
value={pdm}
onSelect={() =>
runCommand(() => {
selected = pdm;
open = false;
query = "";
})}
>
{pdm}
</Command.Item>
{/each}
</Command.List>
{/if}
</Command.Root>
{#if selected} <h1>{selected}</h1>{/if} |
Hey @fredguth, did you ever find a solution to this problem? |
Not exactly. I eventually created a component that was visually equal to |
I think if you want to do custom filtering you need to turn if off explicitly first (see docs): <Command.Root shouldFilter={false}>
<Command.List>
... each statement using the filtered items here... |
This seems more a svelte problem than a cmdk-sv problem, but I am scratching my head once again.
Minimum working example: https://github.com/fredguth/cmd-sk-mwe
In the mwe, my list of options is too big and if I try to render them without filtering it takes too long (not with this json, a bigger one). So, I imagined I could just filter the options on the fly keeping the maximum number of options in a reasonable amout (56 options, for example).
The filteredOptions is changing (as you can see in the console.log), but the Command.List does not change.
The text was updated successfully, but these errors were encountered: