Next.js Discord

Discord Forum

shadcn/ui "command" component

Unanswered
Lilac posted this in #help-forum
Open in Discord
LilacOP
hi, I've been trying to use the command component similar to an autocomplete searchbar, but I can't figure out how to do onclick events for the results. onSelect works but only when you click enter on the item, onClick doesn't work when you click, so i'm just really confused.

3 Replies

LilacOP
<Button
            className="ml-4"
            variant="secondary"
            onClick={() => setOpen(!open)}
          >
            Edit teacher
          </Button>
          <CommandDialog open={open} onOpenChange={setOpen}>
            <CommandInput placeholder="Enter a teacher name to edit..." />
            <CommandList>
              <CommandEmpty>No results found.</CommandEmpty>
              <CommandGroup heading="Teachers">
                {teachers?.map((teacher) => (
                  <CommandItem
                    key={teacher.userid}
                    onSelect={() => console.log(teacher.userid)}
                    className="cursor-pointer"
                  >
                    {teacher.firstname} {teacher.lastname}
                  </CommandItem>
                ))}
              </CommandGroup>
            </CommandList>
          </CommandDialog>
thats my code for creating the command menu
LilacOP
just checked the shadcnui docs and there isnt even anything there