ui icon indicating copy to clipboard operation
ui copied to clipboard

[bug]: Disabled state styles in Command

Open romoguill opened this issue 10 months ago • 5 comments

Describe the bug

I think there is a problem with the disabled styles in Command component, probably because Radix and cmdk uses different ways to use the data-disabled HTML attribute. In CommandPrimitive.Item the default styles for this attribute is:

data-[disabled]:pointer-events-none data-[disabled]:opacity-50

That only works if the component either uses the attribute or not, but not for data-disabled="true" or data-disabled="false".

2 solutions:

  1. Change default styles to data-[disabled="true"]:pointer-events-none data-[disabled="true"]:opacity-50

  2. Change tw config

config = { theme: { extend: { data: { disabled: 'disabled~="true"', }, } } }

It's just a minor issue but the disabled pointer renders the component useless for me until I changed it. Great job on the library by the way 😀

Affected component/components

Command

How to reproduce

  1. Use Command component.
  2. Try to click on the dropdown and see that the cursor is disabled.

Codesandbox/StackBlitz link

No response

Logs

No response

System Info

Versions: 
  "cmdk": "^1.0.0"

Before submitting

  • [X] I've made research efforts and searched the documentation
  • [X] I've searched for existing issues

romoguill avatar Mar 29 '24 13:03 romoguill

I decided to use "cmdk": "^0.2.0" to get around this issue. Using the previous version fixes the disabled item issue.

rajatkumar avatar Mar 29 '24 18:03 rajatkumar

I am also having the same issue in command Item.

const CommandItem = React.forwardRef<
  React.ElementRef<typeof CommandPrimitive.Item>,
  React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
>(({ className, ...props }, ref) => (
  <CommandPrimitive.Item
    ref={ref}
    className={cn(
      "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-none data-[disabled]:opacity-50",
      className
    )}
    {...props}
  />
))

This is the default Code. image

I have removed this data-[disabled]:pointer-events-none data-[disabled]:opacity-50

And now it works image

Based on description, it appears that removing the data-[disabled]:pointer-events-none data-[disabled]:opacity-50 attributes resolves the issue. But I think its not the right way.

I have provided images and code to the problem for visualization and better understanding.

Rahul-ku-Mo avatar Apr 02 '24 12:04 Rahul-ku-Mo

Hi there,

got the same issue after upgrading cmdk to v1.0.0.

Fixed it with @romoguill first solution. Thanks !

31stfr avatar Apr 03 '24 10:04 31stfr

I think its just a matter of updating the disabled selector from: data-[disabled]:... to: data-[disabled='true']:...

p7gg avatar Apr 06 '24 21:04 p7gg

same issue, @p7gg 's solution works well to me

cheung-chifung avatar Apr 22 '24 09:04 cheung-chifung

I spent a lot of time until I found this. A find/replace of data-[disabled] to data-[disabled='true'] got the job done

renanwilliam avatar Aug 02 '24 16:08 renanwilliam