shadcn-ui / ui

Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.
https://ui.shadcn.com
MIT License
69.46k stars 4.14k forks source link

[bug]: combobox framework example isn't working for me #4481

Closed webscriptmaster closed 1 month ago

webscriptmaster commented 1 month ago

Describe the bug

I am trying to use combobox. I followed the guide in the document. https://ui.shadcn.com/docs/components/combobox#combobox But it gave me an error. Is there anyone experienced in this?

Affected component/components

Combobox-form

How to reproduce

Following code provided by the document isn't working.

"use client"

import * as React from "react"
import { CaretSortIcon, CheckIcon } from "@radix-ui/react-icons"

import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
import {
  Command,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
} from "@/components/ui/command"
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from "@/components/ui/popover"

const frameworks = [
  {
    value: "next.js",
    label: "Next.js",
  },
  {
    value: "sveltekit",
    label: "SvelteKit",
  },
  {
    value: "nuxt.js",
    label: "Nuxt.js",
  },
  {
    value: "remix",
    label: "Remix",
  },
  {
    value: "astro",
    label: "Astro",
  },
]

export function ComboboxDemo() {
  const [open, setOpen] = React.useState(false)
  const [value, setValue] = React.useState("")

  return (
    <Popover open={open} onOpenChange={setOpen}>
      <PopoverTrigger asChild>
        <Button
          variant="outline"
          role="combobox"
          aria-expanded={open}
          className="w-[200px] justify-between"
        >
          {value
            ? frameworks.find((framework) => framework.value === value)?.label
            : "Select framework..."}
          <CaretSortIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
        </Button>
      </PopoverTrigger>
      <PopoverContent className="w-[200px] p-0">
        <Command>
          <CommandInput placeholder="Search framework..." className="h-9" />
          <CommandEmpty>No framework found.</CommandEmpty>
          <CommandGroup>
            {frameworks.map((framework) => (
              <CommandItem
                key={framework.value}
                value={framework.value}
                onSelect={(currentValue) => {
                  setValue(currentValue === value ? "" : currentValue)
                  setOpen(false)
                }}
              >
                {framework.label}
                <CheckIcon
                  className={cn(
                    "ml-auto h-4 w-4",
                    value === framework.value ? "opacity-100" : "opacity-0"
                  )}
                />
              </CommandItem>
            ))}
          </CommandGroup>
        </Command>
      </PopoverContent>
    </Popover>
  )
}

Codesandbox/StackBlitz link

combobox

Logs

chunk-ENBTKYLN.js?v=b5a2b780:16659 Uncaught 
TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at Function.from (<anonymous>)
    at A (cmdk.js?v=b5a2b780:180:18)
    at U2 (cmdk.js?v=b5a2b780:146:13)
    at cmdk.js?v=b5a2b780:106:34
    at cmdk.js?v=b5a2b780:374:31
    at Map.forEach (<anonymous>)
    at cmdk.js?v=b5a2b780:374:15
    at commitHookEffectListMount (chunk-ENBTKYLN.js?v=b5a2b780:16904:34)
    at commitLayoutEffectOnFiber (chunk-ENBTKYLN.js?v=b5a2b780:16992:23)
    at commitLayoutMountEffects_complete (chunk-ENBTKYLN.js?v=b5a2b780:17976:17)

System Info

System: Windows 10
Browser: Google Chrome v127

Before submitting

webscriptmaster commented 1 month ago

I can find the solution on https://github.com/shadcn-ui/ui/issues/809

mberd commented 1 month ago

i added CommandList to wrap options under CommandGroup and it solved it

webscriptmaster commented 1 month ago

Thank you @mberd

mberd commented 1 month ago

now i am having an issue with overflow/scrolling with large list... :(

webscriptmaster commented 1 month ago

Have you tried to with scroll-area? https://ui.shadcn.com/docs/components/scroll-area

mberd commented 1 month ago

fyi - https://github.com/pacocoursey/cmdk/issues/244

mberd commented 1 month ago

scroll worked with max-h-...

mberd commented 1 month ago

update: scrolling fix https://github.com/shadcn-ui/ui/issues/3959

webscriptmaster commented 1 month ago

Hi @mberd How can I help you? Can you possibly invite me to your repository? Let's find a better way to improve the features.