ui: [Bug]: Command/Combobox TypeError and Unclickable/Disabled items, cmdk breaking change
Describe the bug
When utilizing a Command component that has been added/updated as of 03/07/2024 ~6PM PST, items cannot be clicked and are disabled. (Additionally some examples using command in the docs are incorrect)
Additionally, <CommandItem>s that are not surrounded by a <CommandList> will crash the application and upon opening the Command component, the error: TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) will be thrown.
This is due to cmdk making a new release with breaking changes: https://github.com/pacocoursey/cmdk/releases
Workaround
This can be fixed by pinning cmdk version to 0.2.1 in package.json See https://github.com/shadcn-ui/ui/issues/2944#issuecomment-1985153126
Solution
https://github.com/shadcn-ui/ui/issues/2944#issuecomment-1985153126 for disabled items fix
https://github.com/shadcn-ui/ui/issues/2944#issuecomment-1986020090 for error fix
Please see PR #2945 to fix these issues
Affected component/components
Command
How to reproduce
- Run
npx shadcn-ui@latest add commandafter 03/07/2024 - Try to use command component
Codesandbox/StackBlitz link
Logs
No response
System Info
cmdk v1.0.0
Before submitting
- I’ve made research efforts and searched the documentation
- I’ve searched for existing issues
About this issue
- Original URL
- State: open
- Created 4 months ago
- Reactions: 66
- Comments: 27
Commits related to this issue
- Revert "build(deps): bump cmdk from 0.2.1 to 1.0.0 (#120)" This reverts commit bcfbf30a683f8a0cd76799494b0c708aca0bd65e. Due to shadcn issue: https://github.com/shadcn-ui/ui/issues/2944 — committed to ttab/elephant-ui by gularsson 4 months ago
- Create combobox component (still a bit buggy but gets fixed in https://github.com/shadcn-ui/ui/issues/2944) — committed to SamichlausDietlikon/samichlaus-dietlikon.ch by jannismilz 3 months ago
- added Combobox from shadcn for token selection and fixed it according to shadcn-ui/ui/issues/2944 — committed to dredshep/AdamantFiSite by dredshep 3 months ago
- fix(command.tsx): fix data-disabled on command items by changing tw selector to data-[disabled='true']. Fix from [shadcn/ui issue #2944](https://github.com/shadcn-ui/ui/issues/2944#issuecomment-19851... — committed to AVGVSTVS96/astroSite by AVGVSTVS96 3 months ago
- Create `CommandMenu` component, use in `react.astro` (#111) * Add shadcn/ui command component * Create CommandMenu component from shadcn example * Create `navigate` function to use `onSelect` prop ... — committed to AVGVSTVS96/astroSite by AVGVSTVS96 3 months ago
- Add data-[disabled='true'] to fix issue from https://github.com/shadcn-ui/ui/issues/2944#issuecomment-1985153126 — committed to AVGVSTVS96/astroSite by AVGVSTVS96 3 months ago
- Update `CommandMenu` styling (#115) * Add data-[disabled='true'] to fix issue from https://github.com/shadcn-ui/ui/issues/2944#issuecomment-1985153126 * Update kbshortcut handling, allow '/' to open... — committed to AVGVSTVS96/astroSite by AVGVSTVS96 3 months ago
- fix: 🚑️ shadcn/ui uses data-[disabled] see: https://github.com/shadcn-ui/ui/issues/2944 — committed to jalezi/cakalne-dobe by jalezi 3 months ago
- Added actions and increased responsiveness Every UUID in a table now functions as a link to its details page. Applied bug fix from https://github.com/shadcn-ui/ui/issues/2944, regarding a bug with c... — committed to Vin-Ren/Invetixia by Vin-Ren 3 months ago
- chore: Update variety of packages Updating the cmdk package required some changes to the ConclusionLicense component, as described in https://github.com/shadcn-ui/ui/issues/2944. Signed-off-by: Joha... — committed to doubleopen-project/dos by lamppu 2 months ago
- chore: Update variety of packages Updating the cmdk package required some changes to the ConclusionLicense component, as described in https://github.com/shadcn-ui/ui/issues/2944. Signed-off-by: Joha... — committed to doubleopen-project/dos by lamppu 2 months ago
- chore: Update variety of packages Updating the cmdk package required some changes to the ConclusionLicense component, as described in https://github.com/shadcn-ui/ui/issues/2944. Signed-off-by: Joha... — committed to doubleopen-project/dos by lamppu 2 months ago
- chore: Update variety of packages Updating the cmdk package required some changes to the ConclusionLicense component, as described in https://github.com/shadcn-ui/ui/issues/2944. Signed-off-by: Joha... — committed to doubleopen-project/dos by lamppu 2 months ago
- fix(theme): :lipstick: Fix shadcn issues caused by cmdk updates. Issues described in this issues thread: https://github.com/shadcn-ui/ui/issues/2944 — committed to jamesMAwalker/visual-econ by jamesMAwalker 2 months ago
- Command Line Not Clickable fixed according to https://github.com/shadcn-ui/ui/issues/2944 — committed to AbhinasRegmi/myblog by AbhinasRegmi 2 months ago
- chore: Update variety of packages Updating the cmdk package required some changes to the ConclusionLicense component, as described in https://github.com/shadcn-ui/ui/issues/2944. Signed-off-by: Joha... — committed to doubleopen-project/dos by lamppu 2 months ago
- chore: Update variety of packages Updating the cmdk package required some changes to the ConclusionLicense component, as described in https://github.com/shadcn-ui/ui/issues/2944. Signed-off-by: Joha... — committed to doubleopen-project/dos by lamppu 2 months ago
- chore: Update variety of packages Updating the cmdk package required some changes to the ConclusionLicense component, as described in https://github.com/shadcn-ui/ui/issues/2944. Signed-off-by: Joha... — committed to doubleopen-project/dos by lamppu 2 months ago
- chore: Update variety of packages Updating the cmdk package required some changes to the ConclusionLicense component, as described in https://github.com/shadcn-ui/ui/issues/2944. Signed-off-by: Joha... — committed to doubleopen-project/dos by lamppu 2 months ago
- chore: Update variety of packages Updating the cmdk package required some changes to the ConclusionLicense component, as described in https://github.com/shadcn-ui/ui/issues/2944. Signed-off-by: Joha... — committed to doubleopen-project/dos by lamppu 2 months ago
Figured out the issue, in cmdk changenotes:
The aria-disabled and aria-selected props will now be set to false, instead of being undefined in https://github.com/pacocoursey/cmdk/commit/c57e6b7f81a5796395c7a016d6b1b2aac9591973It seems that the data-disabled prop is also set to false whereas before the property would not exist at all until being disabled, and
data-[disabled]:pointer-events-nonewill apply even fordata-disabled="false".The fix is to replace
data-[disabled]withdata-[disabled='true']. This should be backwards compatible too! 😃 I see that shadcn/ui uses data-[disabled] in numerous places, may be worth fixing this behavior everywhere. Going to make a PR.I also had to remove
data-[disabled]:pointer-events-none data-[disabled]:opacity-50from hereWhich makes me then wonder, what was it doing in the first place 😃
Hey, I forgot to put in the error, but this is likely because you don’t have a
<CommandList>enclosing your<CommandItems>as I mentioned above, the cmdk version seems to have changed this behavior.Some of the examples for the Command component are incorrect (which I also copy-pastaed (: ) and don’t use a
<CommandList>which I’ve also updated in the PR.tl;dr Try just putting a
<CommandList>around your existing<CommandGroup>s like under the Usage example here: https://ui.shadcn.com/docs/components/commandSome notes, seems like
<CommandItem>needs to be contained somewhere within a<CommandList>.<CommandGroup>alone is no longer sufficient. Upon doing this however, items are now disabled with shadcn/uiEdit: Without a
<CommandList>, the error is:TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))like @shainegordon said, I had to adjust the styles to fix this
note the change
data-[disabled='true']I had the same issue when updating to
cmdkv1. I resolved the issue following your advices:CommandListin the tree;data-[disabled]bydata-[disabled='true'].Thank you! 🙏🏻
This is totally the issue, adding the
<CommandList>around your<CommandItem>'s resolves the TypeError.Any thought on if we should be wrapping
<CommandList>above<CommandGroup>or below?Updating the examples will resolve the crash issue for future users, but the “aria-disabled” breaking change will still need to be updated so anyone with this issue should keep 0.2.1 pinned in their package.json until https://github.com/shadcn-ui/ui/pull/2945 is merged by changing
"cmdk": "^1.0.0"or similarto
"cmdk": "0.2.1"Thanks again @jhnguyen521!
I encountered a similar problem when using the Combobox, but in my situation, the issue wasn’t that it was unclickable or “disabled”; rather, the application would crash whenever the Combobox was opened. This is what I ran into for anyone googling this error:
TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))This is also solved by pinning cmdk version to 0.2.1 in package.json for now. Thanks @jhnguyen521
I had the same issue and fixed with adding CommandList in the tree (check shadcn docs) I replaced data-[disabled] by data-[disabled=‘true’]. I just don’t like that but it’s working
shadcn should lock the dependency version to avoid these bugs due to updates
The solution I use:
In @/components/ui/command.tsx file, you can change the classname on line 120 as follows: “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-none data-[disabled=true]:opacity-50”
+1 Onclick interactions doesn’t work
@matowang
onClickisn’t working for me either, but looking at the PR I figured out to doonSelectinstead! Helps me with my scenario, hopefully can do the same for you! For example I was trying to navigate with it, and got it working with something like this:Taking into account the
data-[disabled='true']instead ofdata-[disabled]fix in the/ui/commandcomponent too!Thanks for the solutions it works after removing
data-[disabled]:pointer-events-none data-[disabled]:opacity-50I wonder if this will be fixed soon.you can downgrade the
cmdkinto previous version 0.2.1Ignore this, I missed the post about changing to
data-[disabled='true'], so I just replaced those classes accordinglyI’'ve also moved the position of
<CommandList>as per the examples, and my combo-box is working again as it shouldI believe it should be above
<CommandGroup>according to all the examples, additionally enclosing<CommandEmpty>but I think it works either way 🤷I don’t think so, the Command component doesn’t do any special handling around
aria-disabledandaria-selected. That should all be handled by the command primitives. Only place I saw that stuff referenced was in the Calendar component.Edit: nvm, it has attributes for the aria-x. It’s just styling, so it doesn’t really matter, but I can just update this in my PR
I’ve used <CommandList /> to wrap both <CommandEmpty /> and <CommandGroup />, but I encountered an unusual issue. Upon inspecting my console, I’ve noticed a multiple warnings indicating that children within the <CommandItem /> components share the same key.
This warning isn’t isolated to just one item; it applies to all <CommandItem />. It appears that <CommandItem /> attempts to render twice with identical keys. I resolved this by appending the map index to my unique ID. The fact that this solution works confirms that the component mounts twice simultaneously.
That aside, there’s a huge lag when the button is clicked to the popover appearing, further confirming my thesis.
This is correct and I hope we will have an official fix soon in next version
Still getting this issue, the fixes listed above work - however clicking on a CommandItem doesn’t close the popover, leaving a meh UX
thanks for the solution, I also wonder this now 😂😂😂
This. Just wrapped my CommandGroup with CommandList and it works now…
The component was built on version 0.2.1, but it automatically updated to version 1.0.0, indicating a major release. This could be due to the automatic incrementation of major versions when installing shadcn
This should be addressed with PR #2945 🤞