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

[Bug]: Combobox component error: Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) #2980

Closed
2 tasks done
aynuayex opened this issue Mar 11, 2024 · 67 comments
Labels
bug Something isn't working

Comments

@aynuayex
Copy link

Describe the bug

i am having the below error when i try to use Combobox component from shadcn-ui library, note that i have directly copy the code from there docs. The error happens when i click on the combobox. i am using the below versions:

    "@hookform/resolvers": "^3.3.4",
    "@radix-ui/react-dialog": "^1.0.5",
    "@radix-ui/react-dropdown-menu": "^2.0.6",
    "@radix-ui/react-icons": "^1.3.0",
    "@radix-ui/react-label": "^2.0.2",
    "@radix-ui/react-popover": "^1.0.7",
    "@radix-ui/react-select": "^2.0.0",
    "@radix-ui/react-slot": "^1.0.2",
    "@tanstack/react-table": "^8.12.0",
    "axios": "^1.6.7",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.1.0",
    "cmdk": "^1.0.0",
    "date-fns": "^3.3.1",
    "dompurify": "^3.0.9",
    "lucide-react": "^0.340.0",
    "react": "^18.2.0",
    "react-day-picker": "^8.10.0",
    "react-dom": "^18.2.0",
    "react-hook-form": "^7.50.1",
    "react-hot-toast": "^2.4.1",
    "react-icons": "^5.0.1",
    "react-router-dom": "^6.22.1",
    "tailwind-merge": "^2.2.1",
    "tailwindcss-animate": "^1.0.7",
    "zod": "^3.22.4"
  },
  "devDependencies": {
    "@types/dompurify": "^3.0.5",
    "@types/node": "^20.11.20",
    "@types/react": "^18.2.56",
    "@types/react-dom": "^18.2.19",
    "@typescript-eslint/eslint-plugin": "^7.0.2",
    "@typescript-eslint/parser": "^7.0.2",
    "@vitejs/plugin-react": "^4.2.1",
    "autoprefixer": "^10.4.17",
    "eslint": "^8.56.0",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-refresh": "^0.4.5",
    "postcss": "^8.4.35",
    "tailwindcss": "^3.4.1",
    "typescript": "^5.2.2",
    "vite": "^5.1.4"
  }

the error

Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at Function.from (<anonymous>)
    at A (cmdk.js?v=958c08d1:173:18)
    at U2 (cmdk.js?v=958c08d1:139:13)
    at cmdk.js?v=958c08d1:99:34
    at cmdk.js?v=958c08d1:367:31
    at Map.forEach (<anonymous>)
    at cmdk.js?v=958c08d1:367:15
    at commitHookEffectListMount (chunk-IIEKGORF.js?v=958c08d1:16904:34)
    at commitLayoutEffectOnFiber (chunk-IIEKGORF.js?v=958c08d1:16992:23)
    at commitLayoutMountEffects_complete (chunk-IIEKGORF.js?v=958c08d1:17976:17)
A @ cmdk.js?v=958c08d1:173
U2 @ cmdk.js?v=958c08d1:139
(anonymous) @ cmdk.js?v=958c08d1:99
(anonymous) @ cmdk.js?v=958c08d1:367
(anonymous) @ cmdk.js?v=958c08d1:367
commitHookEffectListMount @ chunk-IIEKGORF.js?v=958c08d1:16904
commitLayoutEffectOnFiber @ chunk-IIEKGORF.js?v=958c08d1:16992
commitLayoutMountEffects_complete @ chunk-IIEKGORF.js?v=958c08d1:17976
commitLayoutEffects_begin @ chunk-IIEKGORF.js?v=958c08d1:17965
commitLayoutEffects @ chunk-IIEKGORF.js?v=958c08d1:17916
commitRootImpl @ chunk-IIEKGORF.js?v=958c08d1:19349
commitRoot @ chunk-IIEKGORF.js?v=958c08d1:19273
performSyncWorkOnRoot @ chunk-IIEKGORF.js?v=958c08d1:18891
flushSyncCallbacks @ chunk-IIEKGORF.js?v=958c08d1:9135
(anonymous) @ chunk-IIEKGORF.js?v=958c08d1:18623
Show 15 more frames
Show less
chunk-IIEKGORF.js?v=958c08d1:16659 Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at Function.from (<anonymous>)
    at A (cmdk.js?v=958c08d1:173:18)
    at U2 (cmdk.js?v=958c08d1:139:13)
    at cmdk.js?v=958c08d1:99:34
    at cmdk.js?v=958c08d1:367:31
    at Map.forEach (<anonymous>)
    at cmdk.js?v=958c08d1:367:15
    at commitHookEffectListMount (chunk-IIEKGORF.js?v=958c08d1:16904:34)
    at invokeLayoutEffectMountInDEV (chunk-IIEKGORF.js?v=958c08d1:18295:19)
    at invokeEffectsInDev (chunk-IIEKGORF.js?v=958c08d1:19697:19)
A @ cmdk.js?v=958c08d1:173
U2 @ cmdk.js?v=958c08d1:139
(anonymous) @ cmdk.js?v=958c08d1:99
(anonymous) @ cmdk.js?v=958c08d1:367
(anonymous) @ cmdk.js?v=958c08d1:367
commitHookEffectListMount @ chunk-IIEKGORF.js?v=958c08d1:16904
invokeLayoutEffectMountInDEV @ chunk-IIEKGORF.js?v=958c08d1:18295
invokeEffectsInDev @ chunk-IIEKGORF.js?v=958c08d1:19697
commitDoubleInvokeEffectsInDEV @ chunk-IIEKGORF.js?v=958c08d1:19680
flushPassiveEffectsImpl @ chunk-IIEKGORF.js?v=958c08d1:19499
flushPassiveEffects @ chunk-IIEKGORF.js?v=958c08d1:19443
commitRootImpl @ chunk-IIEKGORF.js?v=958c08d1:19412
commitRoot @ chunk-IIEKGORF.js?v=958c08d1:19273
performSyncWorkOnRoot @ chunk-IIEKGORF.js?v=958c08d1:18891
flushSyncCallbacks @ chunk-IIEKGORF.js?v=958c08d1:9135
(anonymous) @ chunk-IIEKGORF.js?v=958c08d1:18623
Show 16 more frames
Show less
react-router-dom.js?v=958c08d1:3479 Error handled by React Router default ErrorBoundary: TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at Function.from (<anonymous>)
    at A (cmdk.js?v=958c08d1:173:18)
    at U2 (cmdk.js?v=958c08d1:139:13)
    at cmdk.js?v=958c08d1:99:34
    at cmdk.js?v=958c08d1:367:31
    at Map.forEach (<anonymous>)
    at cmdk.js?v=958c08d1:367:15
    at commitHookEffectListMount (chunk-IIEKGORF.js?v=958c08d1:16904:34)
    at invokeLayoutEffectMountInDEV (chunk-IIEKGORF.js?v=958c08d1:18295:19)
    at invokeEffectsInDev (chunk-IIEKGORF.js?v=958c08d1:19697:19)

Affected component/components

Combobox

How to reproduce

1, create a new project using vite, just be sure to use the versions below i mention
2, add the combobox component and any other components that depend on it.
3, and copy paste the code from the docs and run your application

Codesandbox/StackBlitz link

No response

Logs

No response

System Info

Operating System: Windows 10
Browser: Chrome
Node.js Version (if applicable): v20.9.0
React Version: ^18.2.0,
React Router Version: 6.22.1

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
@aynuayex aynuayex added the bug Something isn't working label Mar 11, 2024
@aynuayex
Copy link
Author

This seems to come from the library called cmdk cause when i fallback to older version ^0.2.0 it works with out problem, the newer version ^1.0.0. The Comobox component uses that library. Any fixes @pacocoursey, thanks in advance.

@k1eu
Copy link

k1eu commented Mar 11, 2024

In the v.1 release notes https://github.com/pacocoursey/cmdk/releases/tag/v1.0.0
Rendering the Command.List part (CommandList if using shadcn) is now mandatory.

So you need to add the CommandList beneath the Command component in your usecase to work @aynuayex

@aynuayex
Copy link
Author

Thanks, but there are also other breaking change such as can't select the items and all the available items are grayed out ,hover and other styles not working , so the Combobox component should be updated to reflect the changes

@k1eu
Copy link

k1eu commented Mar 11, 2024

@aynuayex yes, here's the thread with the issues already open: #2944, and the fixes needed - so maybe we can link to that and close this one :D

@aynuayex
Copy link
Author

aynuayex commented Mar 26, 2024 via email

@dialite
Copy link

dialite commented Mar 27, 2024

I just had to modify the cmdk to an older version of ^0.2.1 and it worked perfectly well.

@LogicalOgbonna
Copy link

Wrapping CommandList around CommandItem(s) worked for me.

<CommandGroup>
  <CommandList>
    {options.map((option) => (
      <CommandItem
        key={option.value}
        value={option.value}
        onSelect={(currentValue) => {
          setValue(currentValue === value ? "" : currentValue);
          setOpen(false);
          onSelect(currentValue);
        }}
      >
        <CheckCircledIcon
          className={cn(
            "mr-2 h-4 w-4",
            value === option.value ? "opacity-100" : "opacity-0"
          )}
        />
        {option.label}
      </CommandItem>
    ))}
  </CommandList>
</CommandGroup>

@Gimhan001
Copy link

Gimhan001 commented Mar 29, 2024

Is this issue fixed ? I got the same issue in NextJs project.

Gyozadaigaku added a commit to Gyozadaigaku/shadcn-design-system that referenced this issue Mar 30, 2024
@EggsLeggs
Copy link

Is this issue fixed ? I got the same issue in NextJs project.

Did you try the fix above your comment, should fix your issue. The docs haven't been updated yet. Might be worth putting in a pull request if no one has already.

@danilo-css
Copy link

Is this issue fixed ? I got the same issue in NextJs project.

Did you try the fix above your comment, should fix your issue. The docs haven't been updated yet. Might be worth putting in a pull request if no one has already.

Wrapping the items inside CommandGroup in CommandList fixes the issue, but creates other issue, all the items get greyed out and unclickable:

image

This is the code I am using:

<CommandGroup>
  <CommandList>
    {frameworks.map((framework) => (
      <CommandItem
        key={framework.value}
        value={framework.value}
        onSelect={(currentValue) => {
          setValue(currentValue === value ? "" : currentValue);
          setOpen(false);
        }}
      >
        <Check
          className={cn(
            "mr-2 h-4 w-4",
            value === framework.value ? "opacity-100" : "opacity-0"
          )}
        />
        {framework.label}
      </CommandItem>
    ))}
  </CommandList>
</CommandGroup>

@aynuayex
Copy link
Author

aynuayex commented Apr 1, 2024

@danilo-css @Gimhan001 Since You guys are very bored to read the issue that i have mentioned to solve the grayed out problem of the list items displayed, i will generalize the answer here once and for all the time.so here is the code that prevents the above error from happening:

<Popover open={open} onOpenChange={setOpen}>
      <PopoverTrigger asChild>
        <Button
          variant="outline"
          size={"sm"}
          role="combobox"
          aria-expanded={open}
          aria-label="Select Department"
          className="w-[200px] justify-between dark:text-white"
        >
          <FcDepartment className="mr-2 hidden lg:block" />
          {value
            ? frameworks.find((framework) => framework.value === value)?.label
            : "Select department"}
          <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50 hidden lg:block" />
        </Button>
      </PopoverTrigger>
      <PopoverContent className="w-[200px] p-0">
        <Command>
          <CommandInput placeholder="Search department..." />
          <CommandList>
            <CommandEmpty>No department found.</CommandEmpty>
            <CommandGroup>
              {frameworks.map((framework) => (
                <CommandItem
                  key={framework.value}
                  value={framework.value}
                  onSelect={(currentValue) => {
                    setValue(currentValue === value ? "" : currentValue);
                    setOpen(false);
                  }}
                >
                  <Check
                    className={cn(
                      "mr-2 h-4 w-4",
                      value === framework.value ? "opacity-100" : "opacity-0"
                    )}
                  />
                  {framework.label}
                </CommandItem>
              ))}
            </CommandGroup>
          </CommandList>
        </Command>
      </PopoverContent>
    </Popover>

so, warping the CommandItem with CommandList or as in the docs warp CommandGroup including CommandEmpty with CommandList.

to solve the list items being grayed out, open Command component by going to components/ui/command.tsx and look for const CommandItem and replace every data-[disabled] with data-[disabled='true'] in the className prop.Now you are good to go!
This is because, in cmdk changenotes:
The aria-disabled and aria-selected props will now be set to false by default, instead of being undefined.

@tranduybau
Copy link

@aynuayex Here is my code:

<Popover open={open} onOpenChange={setOpen}>
      <PopoverTrigger asChild>
        <Button
          variant="outline"
          role="combobox"
          aria-expanded={open}
          aria-label="Select Department"
        >
          {value
            ? frameworks.find((framework) => framework.value === value)?.label
            : "Select department"}
          <AppIcon
            src="/svg/chevron-down.svg#id"
            className="ml-2 hidden h-4 w-4 shrink-0 opacity-50 lg:block"
          />
        </Button>
      </PopoverTrigger>
      <PopoverContent className="w-[200px] p-0">
        <Command>
          <CommandInput placeholder="Search department..." />
          <CommandList>
            <CommandEmpty>No department found.</CommandEmpty>
            <CommandGroup>
              {frameworks.map((framework) => (
                <CommandItem
                  key={framework.value}
                  value={framework.value}
                  onSelect={(currentValue) => {
                    setValue(currentValue === value ? "" : currentValue);
                    setOpen(false);
                  }}
                >
                  {framework.label}

                  <AppIcon src="/svg/check.svg#id" />
                </CommandItem>
              ))}
            </CommandGroup>
          </CommandList>
        </Command>
      </PopoverContent>
    </Popover>

And it still not working as well. Can't click the item

@aynuayex
Copy link
Author

aynuayex commented Apr 3, 2024

@tranduybau please read this(it is the comment just above your comment at the end of it.

@tranduybau
Copy link

@tranduybau please read this(it is the comment just above your comment at the end of it.

Turn out the problems is millions, I used your code but it didnt hot reload. I re-run the web and it's all good, Thank you mate :D Have a good day.

@Priyanshu85
Copy link

image

I got this problem after using your code @aynuayex

@aynuayex
Copy link
Author

aynuayex commented Apr 3, 2024

@Priyanshu85 sorry for the late reply and the error.it is caused because of my implementation in my code, i add className since i have addtional classNames to style the combobox i.e, i have made the combobox(the above code) a component and passing additional styles.
so,in your case just remove , className or totally change the className prop with className="w-[200px] justify-between dark:text-white"
or review the above code i have updated it.

@tranduybau
Copy link

Hi @aynuayex , today I faced another issue is can't scroll when the content is too long, Have you ever seen that before?

@MaxsaDev
Copy link

MaxsaDev commented Apr 9, 2024

@aynuayex 🤝
Your solution worked for me. 4 hours of hysteria were wasted before your magical message.

@tsybko22
Copy link

tsybko22 commented Apr 9, 2024

to solve the list items being grayed out, open Command component by going to components/ui/command.tsx and look for const CommandItem and replace every data-[disabled] with data-[disabled='true'] in the className prop.Now you are good to go!

It works fine! Just do not forget about this detail.

@ode96-dev
Copy link

Wrapping CommandList around CommandItem(s) worked for me.

<CommandGroup>
  <CommandList>
    {options.map((option) => (
      <CommandItem
        key={option.value}
        value={option.value}
        onSelect={(currentValue) => {
          setValue(currentValue === value ? "" : currentValue);
          setOpen(false);
          onSelect(currentValue);
        }}
      >
        <CheckCircledIcon
          className={cn(
            "mr-2 h-4 w-4",
            value === option.value ? "opacity-100" : "opacity-0"
          )}
        />
        {option.label}
      </CommandItem>
    ))}
  </CommandList>
</CommandGroup>

Best option!thank you!

@BienvenidoBoriko
Copy link

@danilo-css @Gimhan001 Since You guys are very bored to read the issue that i have mentioned to solve the grayed out problem of the list items displayed, i will generalize the answer here once and for all the time.so here is the code that prevents the above error from happening:

<Popover open={open} onOpenChange={setOpen}>
      <PopoverTrigger asChild>
        <Button
          variant="outline"
          size={"sm"}
          role="combobox"
          aria-expanded={open}
          aria-label="Select Department"
          className="w-[200px] justify-between dark:text-white"
        >
          <FcDepartment className="mr-2 hidden lg:block" />
          {value
            ? frameworks.find((framework) => framework.value === value)?.label
            : "Select department"}
          <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50 hidden lg:block" />
        </Button>
      </PopoverTrigger>
      <PopoverContent className="w-[200px] p-0">
        <Command>
          <CommandInput placeholder="Search department..." />
          <CommandList>
            <CommandEmpty>No department found.</CommandEmpty>
            <CommandGroup>
              {frameworks.map((framework) => (
                <CommandItem
                  key={framework.value}
                  value={framework.value}
                  onSelect={(currentValue) => {
                    setValue(currentValue === value ? "" : currentValue);
                    setOpen(false);
                  }}
                >
                  <Check
                    className={cn(
                      "mr-2 h-4 w-4",
                      value === framework.value ? "opacity-100" : "opacity-0"
                    )}
                  />
                  {framework.label}
                </CommandItem>
              ))}
            </CommandGroup>
          </CommandList>
        </Command>
      </PopoverContent>
    </Popover>

so, warping the CommandItem with CommandList or as in the docs warp CommandGroup including CommandEmpty with CommandList.

to solve the list items being grayed out, open Command component by going to components/ui/command.tsx and look for const CommandItem and replace every data-[disabled] with data-[disabled='true'] in the className prop.Now you are good to go! This is because, in cmdk changenotes: The aria-disabled and aria-selected props will now be set to false by default, instead of being undefined.

tanks this work

@aynuayex
Copy link
Author

Hi @aynuayex , today I faced another issue is can't scroll when the content is too long, Have you ever seen that before?

No, I haven't, mine works fine when the content is too long. what version are you using?

@tranduybau
Copy link

he issue came from the modal. Didnt have the props modal={true}. Resolved :D

@tier3guy
Copy link

In the v.1 release notes https://github.com/pacocoursey/cmdk/releases/tag/v1.0.0 Rendering the Command.List part (CommandList if using shadcn) is now mandatory.

So you need to add the CommandList beneath the Command component in your usecase to work @aynuayex

Thanks for helping !! This solution worked for me.

@idaix
Copy link

idaix commented Apr 19, 2024

use lower version of "cmdk": "^1.0.0" ====> "cmdk": "^0.2.0 "

@aynuayex
Copy link
Author

aynuayex commented Jul 9, 2024

className should be this:

"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-auto data-[disabled='true']:opacity-50"

@kyusungpark No no, unless there is new thing in your code or because of how you use react-hook-form with it. also cmdk has no new version releases,so it should lool like this
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled='true']:pointer-events-auto data-[disabled='true']:opacity-50"

@Azoonex
Copy link

Azoonex commented Jul 9, 2024

@aynuayex The problem was solved for me,bro ,thank you for you time

@kyusungpark
Copy link

For Combo box UI

"use client";

import * as React from "react";
import { Check, ChevronsUpDown } from "lucide-react";
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";

interface ComboboxProps {
  options: {
    label: string;
    value: string;
  }[];
  value?: string;
  onChange: (value: string) => void;
}

export const Combobox = (props: ComboboxProps) => {
  const [open, setOpen] = React.useState(false);

  return (
    <Popover open={open} onOpenChange={setOpen}>
      <PopoverTrigger asChild>
        <Button
          variant="outline"
          role="combobox"
          aria-expanded={open}
          className="w-full justify-between"
        >
          {props.value
            ? props.options.find((option) => option.value === props.value)
                ?.label
            : "Select option..."}
          <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
        </Button>
      </PopoverTrigger>
      <PopoverContent className="w-full p-0">
        <Command>
          <CommandInput placeholder="Search for option..." />
          <CommandEmpty>No option found.</CommandEmpty>
          <CommandGroup>
            {props.options.map((option) => (
              <CommandItem
                key={option.value}
                value={option.value}
                onSelect={() => {
                  props.onChange(
                    option.value === props.value ? "" : option.value
                  );
                  setOpen(false);
                }}
              >
                <Check
                  className={cn(
                    "mr-2 h-4 w-4",
                    props.value === option.value ? "opacity-100" : "opacity-0"
                  )}
                />
                {option.label}
              </CommandItem>
            ))}
          </CommandGroup>
        </Command>
      </PopoverContent>
    </Popover>
  );
};

Example implementation:
  const [categories, setCategories] = useState<any>();

  useEffect(() => {
    (async () => {
      const categories = await getCategories();

      setCategories(categories);
    })();
  }, []);

  const options: any = categories?.map((category: any) => ({
    label: category?.name,
    value: category?.id,
  }));
//inside form
                  <FormField
                    control={form.control}
                    name="category_id"
                    render={({ field }) => (
                      <FormItem>
                        <FormLabel>Categories</FormLabel>
                        <FormControl>
                          <Combobox
                            item={"category"}
                            options={options}
                            {...field}
                          />
                        </FormControl>
                        <FormMessage />
                      </FormItem>
                    )}
                  />

thanks, but any idea why I need to have a separate state for open? Isn't PopoverTrigger supposed to hande this? Also, having data-[disabled='true']:pointer-events-auto still did not work me. I hadd to add a new state to mange open/close and set data-[disabled]:pointer-events-auto else it wouldn't work

@Azoonex
Copy link

Azoonex commented Jul 10, 2024

@kyusungpark Use CommandList

 <Command dir="rtl">
            <CommandInput dir="rtl" placeholder={nameAction} />
            <CommandList>
              <CommandEmpty>not found!</CommandEmpty>
              <CommandGroup>
                {data.map((item) => (
                  <CommandItem
                    key={item.id}
                    value={item.id.toString()}
                    onSelect={() => handleSelect(item.id)}
                    className="hover:bg-red-950 my-1 text-end cursor-pointer"
                  >
                    {item.name} {item?.title}
                    <Check
                      className={cn(
                        "mr-4 h-4 w-4",
                        selectedItem === item.id ? "opacity-100" : "opacity-0"
                      )}
                    />
                  </CommandItem>
                ))}
              </CommandGroup>
            </CommandList>
          </Command>
          
          

@kyusungpark
Copy link

kyusungpark commented Jul 10, 2024

@Azoonex

Yeah, that's pretty much what I have

              <Command>
                <CommandInput placeholder={placeholder} />
                <CommandList>
                  <CommandEmpty>Not found.</CommandEmpty>
                  <CommandGroup>
                    {options.map((option) => (
                      <CommandItem
                        value={option.label}
                        key={option.value}
                        onSelect={() => {
                          onSelect(option.value, option.id);
                          setIsOpen(false);
                        }}
                      >
                        <Check
                          className={cn(
                            'mr-2 h-4 w-4',
                            option.value === field.value ? 'opacity-100' : 'opacity-0',
                          )}
                        />
                        {option.label}
                      </CommandItem>
                    ))}
                  </CommandGroup>
                </CommandList>
              </Command>

'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled=false]:pointer-events-auto data-[disabled=true]:opacity-50',

If I set data-[disabled=false]:pointer-events-auto to true it doesn't work

@eedeebee
Copy link

Why is this issue marked as closed?

@eedeebee
Copy link

eedeebee commented Jul 11, 2024

I edited the command.tsx component per advice here... and wrapped my stuff with CommandList and it now displays and things aren't grayed out but the component doesn't work - typing or clicking in it doesn't ever search or select anything. I'm tryingto use the component inside a Sheet - this crappy behavior doesn't seem to exist if I use it outside of the Sheet :(

danmaninc added a commit to duckduck-team/quackit that referenced this issue Jul 11, 2024
@kyusungpark
Copy link

I edited the command.tsx component per advice here... and wrapped my stuff with CommandList and it now displays and things aren't grayed out but the component doesn't work - typing or clicking in it doesn't ever search or select anything. I'm tryingto use the component inside a Sheet - this crappy behavior doesn't seem to exist if I use it outside of the Sheet :(

I use it with a form that is inside is a sheet and what I have above works. Did you get it to close on click though? I had to manually add state to close it onClick

@eedeebee
Copy link

eedeebee commented Jul 11, 2024 via email

@eedeebee
Copy link

I've got a reproducible case of combobox as described here - with the edits to the className and use of basically working outside of a and inside a , the keyboard and mouse inputs are ignored. Guessing another shadcn combobox bug.

@Azoonex
Copy link

Azoonex commented Jul 12, 2024

@kyusungpark
@eedeebee I had the same problem, I fixed it / This replaces the command component code

"use client"

import * as React from "react"
import { type DialogProps } from "@radix-ui/react-dialog"
import { Command as CommandPrimitive } from "cmdk"
import { Search } from "lucide-react"

import { cn } from "@/lib/utils"
import { Dialog, DialogContent } from "@/components/ui/dialog"

const Command = React.forwardRef<
  React.ElementRef<typeof CommandPrimitive>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive>
>(({ className, ...props }, ref) => (
  <CommandPrimitive
    ref={ref}
    className={cn(
      "flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
      className
    )}
    {...props}
  />
))
Command.displayName = CommandPrimitive.displayName

interface CommandDialogProps extends DialogProps {}

const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
  return (
    <Dialog {...props}>
      <DialogContent className="overflow-hidden p-0 shadow-lg">
        <Command className="[&_[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">
          {children}
        </Command>
      </DialogContent>
    </Dialog>
  )
}

const CommandInput = React.forwardRef<
  React.ElementRef<typeof CommandPrimitive.Input>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>
>(({ className, ...props }, ref) => (
  <div className="flex items-center border-b px-3" cmdk-input-wrapper="">
    <Search className="mr-2 h-4 w-4 shrink-0 opacity-50" />
    <CommandPrimitive.Input
      ref={ref}
      className={cn(
        "flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
        className
      )}
      {...props}
    />
  </div>
))

CommandInput.displayName = CommandPrimitive.Input.displayName

const CommandList = React.forwardRef<
  React.ElementRef<typeof CommandPrimitive.List>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>
>(({ className, ...props }, ref) => (
  <CommandPrimitive.List
    ref={ref}
    className={cn("max-h-[300px]  overflow-y-auto overflow-x-hidden", className)}
    {...props}
  />
))

CommandList.displayName = CommandPrimitive.List.displayName

const CommandEmpty = React.forwardRef<
  React.ElementRef<typeof CommandPrimitive.Empty>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
>((props, ref) => (
  <CommandPrimitive.Empty
    ref={ref}
    className="py-6 text-center text-sm"
    {...props}
  />
))

CommandEmpty.displayName = CommandPrimitive.Empty.displayName

const CommandGroup = React.forwardRef<
  React.ElementRef<typeof CommandPrimitive.Group>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>
>(({ className, ...props }, ref) => (
  <CommandPrimitive.Group
    ref={ref}
    className={cn(
      "overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
      className
    )}
    {...props}
  />
))

CommandGroup.displayName = CommandPrimitive.Group.displayName

const CommandSeparator = React.forwardRef<
  React.ElementRef<typeof CommandPrimitive.Separator>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>
>(({ className, ...props }, ref) => (
  <CommandPrimitive.Separator
    ref={ref}
    className={cn("-mx-1 h-px bg-border", className)}
    {...props}
  />
))
CommandSeparator.displayName = CommandPrimitive.Separator.displayName

const CommandItem = React.forwardRef<
  React.ElementRef<typeof CommandPrimitive.Item>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
>(({ className, ...props }, ref) => (
  <CommandPrimitive.Item
    ref={ref}
    className={cn(
      "flex justify-start items-center text_right select-none rounded-sm py-2 text-xs outline-none aria-selected:bg-blue-100 aria-selected:text-black ",
      className
    )}
    {...props}
  />
))

CommandItem.displayName = CommandPrimitive.Item.displayName

const CommandShortcut = ({
  className,
  ...props
}: React.HTMLAttributes<HTMLSpanElement>) => {
  return (
    <span
      className={cn(
        "ml-auto text-xs hover:text-black tracking-widest text-muted-foreground",
        className
      )}
      {...props}
    />
  )
}
CommandShortcut.displayName = "CommandShortcut"

export {
  Command,
  CommandDialog,
  CommandInput,
  CommandList,
  CommandEmpty,
  CommandGroup,
  CommandItem,
  CommandShortcut,
  CommandSeparator,
}

@Azoonex
Copy link

Azoonex commented Jul 12, 2024

@kyusungpark
@eedeebee How to use

import * as React from "react";
import { Check, ChevronsUpDown } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command";
import { Text } from "@radix-ui/themes";
import { TypesearchSelected } from "../../types/TypeAllDoctors.type";
import { cn } from "@/lib/utils";

function ComboboxDemo({
  label,
  data,
  nameAction,
  onChange,
  selectedItem,
  onSelect,
}: TypesearchSelected) {
  const [open, setOpen] = React.useState(false);

  const handleSelect = (currentValue: number) => {
    console.log("Selected Value:", currentValue);
    onSelect(currentValue); // Call onSelect prop with the selected value
    setOpen(false);
    onChange(currentValue);
  };

  return (
    <div className="border-b-[1px] border-gray-200 pb-3">
      <Text mb={"3"} color="gray" className="float-right">
        {label}
      </Text>
      <Popover open={open} onOpenChange={setOpen}>
        <PopoverTrigger dir="rtl" asChild>
          <Button
            variant="outline"
            role="combobox"
            aria-expanded={open}
            className="w-full justify-between hover:bg-white hover:text-black"
            onClick={() => setOpen((prevOpen) => !prevOpen)}
          >
            {selectedItem !== null ? (
              data.find((item) => item.id === selectedItem)?.name ||
              data.find((item) => item.id === selectedItem)?.title ||
              nameAction
            ) : (
              nameAction
            )}
            <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
          </Button>
        </PopoverTrigger>

        <PopoverContent dir="ltr" className="w-[320px] p-0">
          <Command>
            <CommandInput dir="rtl" placeholder={nameAction} />
            <CommandList>
                <CommandEmpty>not found!</CommandEmpty>
              <CommandGroup>
                {data.map((item) => (
                  <CommandItem
                    dir="rtl"
                    key={item.id}
                    onSelect={() => handleSelect(item.id)}
                    className="my-1 text-end cursor-pointer"
                    aria-selected={selectedItem === item.id}
                  >
                    {item.name} {item?.title}
                    <Check
                      className={cn(
                        "mr-4 h-4 w-4",
                        selectedItem === item.id ? "opacity-100" : "opacity-0"
                      )}
                    />
                  </CommandItem>
                ))}
              </CommandGroup>
            </CommandList>
          </Command>
        </PopoverContent>
      </Popover>
    </div>
  );
}

export default ComboboxDemo;

@eedeebee
Copy link

So I was able to address part of thigns not working in Sheet by

% npm i @radix-ui/react-dismissable-layer

I can now get mouse events, but still no keyboard events. Also the combo doesn't scroll when it's long. I guess that's left to the reader still.

@Azoonex
Copy link

Azoonex commented Jul 12, 2024

I understand that I had the same problem and there is a method tailwind nam aria-selected, If you remove it, you can hover it with the mouse

danmaninc added a commit to duckduck-team/quackit that referenced this issue Jul 12, 2024
@kyusungpark
Copy link

So I was able to address part of thigns not working in Sheet by

% npm i @radix-ui/react-dismissable-layer

I can now get mouse events, but still no keyboard events. Also the combo doesn't scroll when it's long. I guess that's left to the reader still.

I do the same. I have a sheet and inside a Form which has a combobox. Can't get scroll to work.

@Azoonex
Copy link

Azoonex commented Jul 13, 2024

@kyusungpark
#2980 (comment)
Check this component and the next one

@logemann
Copy link

So this issue is closed and the docs are still wrong?

@LogicalOgbonna
Copy link

So this issue is closed and the docs are still wrong?

@logemann, mind creating a PR?

@Azoonex
Copy link

Azoonex commented Jul 19, 2024

@logemann Reporte a problem!

@logemann
Copy link

There was a problem called "issue" where we just typing in messages. Closing this means its fixed right? I definitely wont report that an issue was "closed" w/o fixing it.....

@Azoonex
Copy link

Azoonex commented Jul 19, 2024

Maybe there is a problem or there is no access

@maxgfr
Copy link

maxgfr commented Jul 23, 2024

For me, this comment : #2980 (comment) helps me a lot. just by wrapping the CommandItem in CommandList

@Azoonex
Copy link

Azoonex commented Jul 24, 2024

it's true

@mengxi-ream
Copy link

Why this issue is closed without PR?
when I run npx shadcn-ui@latest add command, I still got the wrong code with data-[disabled]

@othman2408
Copy link

Why this issue is closed without PR? when I run npx shadcn-ui@latest add command, I still got the wrong code with data-[disabled]

Same here

@Meshaal-A
Copy link

I've resolved the issue I was encountering after importing CommandList.

Here's what I did to fix it:

Double-checked that CommandList was correctly imported and wrapped my list items within CommandList.

Thats it.

@sreenivasanac
Copy link

I was trying to debug this in my code thinking I had missed a NULL or undefined variable (.map iteration) or deconstruction error. Having such bugs in common UI components should be resolved and any new version we import should not have this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests