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

Separator always appears at top of list #283

Open
fauxparse opened this issue Jul 13, 2024 · 1 comment
Open

Separator always appears at top of list #283

fauxparse opened this issue Jul 13, 2024 · 1 comment

Comments

@fauxparse
Copy link

{results.map((result) => (
  <Command.Item key={result.id}>{result.label}</Fragment>
)}
<Command.Separator alwaysRender={results.length > 0} />
<Command.Item value={query} onSelect={() => add(query)}>
  Add “{query}”
</Command.Item>

The separator element always appears at the top of the list for some reason, regardless of where it is in the source.

@arthurjdam
Copy link

Are you manually filtering the results and using <Command shouldFilter={false}>?
This works fine:

const [query, setQuery] = useState('');
const filteredResults = useMemo(
    () =>
        query.length === 0 
            ? results
            : results.filter((result) => {
                    return result.label
                        .toLowerCase()
                        .includes(query.toLowerCase());
                }),
    [query]
);

return (
    <Command shouldFilter={false}>
        <Command.Input value={query} onValueChange={setQuery} />
        <Command.List>
            <Command.Group>
                {filteredResults.map((result) => (
                    <Command.Item key={result.id}>
                        {result.label}
                    </Command.Item>
                ))}
                <Command.Separator
                    alwaysRender={filteredResults.length > 0}
                />
                <Command.Item value={query}>Add {query}</Command.Item>
            </Command.Group>
        </Command.List>
    </Command>
);

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

No branches or pull requests

2 participants