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
68.57k stars 4.06k forks source link

[bug]: CommandItem is disabled even if data-disabled is set to false. #4349

Open bleedingAyush opened 1 month ago

bleedingAyush commented 1 month ago

Describe the bug

I was trying to create team selector so I copied the code from your repo TeamSwitcher.tsx

After doing everything as expected the CommandItem was not working. After inspecting the devtools I found out that it is disabled

.data-\[disabled\]\:pointer-events-none[data-disabled] {
    pointer-events: none;
}
  <CommandGroup>
                <DialogTrigger asChild>
                  <CommandItem
                    onSelect={() => {
                      setOpen(false);
                      setShowNewTeamDialog(true);
                    }}
                  >
                    <CirclePlus className="mr-2 h-5 w-5" />
                    Create Team
                  </CommandItem>
                </DialogTrigger>
              </CommandGroup>

Affected component/components

CommandItem

How to reproduce

  1. Install shadncn/ui and command
  2. Copy the code from shadcn/ui repo for the component TeamSwitcher.tsx
  3. After opening the Command the items are not selectable.

Codesandbox/StackBlitz link

No response

Logs

No response

System Info

Sec-Ch-Ua-Platform:
"Windows"
User-Agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0

Before submitting

jqjjian commented 1 month ago

Yes, I have encountered the same problem, which has not been solved yet.

yeonsubak commented 1 month ago

I've submitted a PR for fixing this bug:

Please check the video in the bug replication steps and if you are experiencing the same bug, here are the fixes:

  1. (Simplest) Downgrade cmdk to @0.2.1 on your project's package.json.
  2. Modify CommandItem component as below
    const CommandItem = React.forwardRef<
      React.ElementRef<typeof CommandPrimitive.Item>,
      React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
    >(({ className, disabled, ...props }, ref) => (
      <CommandPrimitive.Item
        ref={ref}
        disabled={disabled}
        className={cn(
          "relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground",
          disabled ? "opacity-50" : '',
          className
        )}
        {...props}
      />
    ))