You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
First item is selected by default - can this be disabled? #171
Just wondering whether the default behaviour of selecting the first item in the list is some sort of accessibility requirement (if so, could you please point to the docs?), and whether this is something the can be disabled?
I was looking for something like selectFirstItem={false} but couldn't find such API.
Reacted by Rob Morieson, Moshe Simantov, Kasun Peiris, Robert Sun, masewo, Ben Chilcott, Lovro Zagar, Thomas Luc, Alfonso Andrés López Molina, Hoang Huy Pham and 15 more
It would be great if there was a way to specify which item should be selected first.
Actually, this was easy once I figured out how. You can set the value prop on the Command component to the item you want to be selected first.
Reacted by Kasun Peiris, Jason Belich, Anders Pedersen, Alfredo Diaz, Pedro Almeida, Siraj Tahra, Advait Junnarkar, Hem Bahadur Pun, José de Matos Moreira and Jake
+1 on this being a somewhat arbitrary requirement. We should have the flexibility to set this
Reacted by Ben Chilcott, Lovro Zagar, Alfonso Andrés López Molina, Michael Lauridsen, Edward Shturman, Pavel Belyaev, Jason Belich, Zach Lankton, Alfredo Diaz, stefan-huck and 2 more
@pacocoursey Do I understand correctly that in v1.0 it's still not possible to disable the auto-select of the first item? Is it some sort of accessibility concern?
If the component sits below the fold, the page will always scroll to the first selected item, which is a pain. Any way to disable any kind of selection on render would be much appreciated.
would be cool to get an API for this. selectFirstItem={false} would do the trick.
Example where it comes in handy: Let's say you use the UI for a search input that can display some suggestions. You want to write into the input and submit the search query only OR you wanna select an item (via keyboard or mouse) and trigger the suggestion.
Reacted by 배정원(Jungwon Bae), Caio Viotti and Siraj Tahra
This is the solution to the problem, is sets the data-selected and aria-selected to true on the selected one. but we do not need to disable disablePointerSelection. just set the defaultValue.
if you want to disable the selection of the first item just set the default value to a non existing value, but not undefined
This solution preserves selected value and allows keyboard navigation. <Command defaultValue={value} disablePointerSelection={true}>
This is the solution to the problem, is sets the data-selected and aria-selected to true on the selected one. but we do not need to disable disablePointerSelection. just set the defaultValue. if you want to disable the selection of the first item just set the default value to a non existing value, but not undefined
Activity
JamesParkinSonos commentedon Aug 22, 2023
It would be great if there was a way to specify which item should be selected first.Actually, this was easy once I figured out how. You can set the value prop on the Command component to the item you want to be selected first.
moshest commentedon Oct 23, 2023
My solution is to add a hidden value to it will be automatically selected:
The hidden class make sure it will not be visible but still controlled and selected by
cmdk.sunwrobert commentedon Dec 1, 2023
+1 on this being a somewhat arbitrary requirement. We should have the flexibility to set this
moroshko commentedon Mar 14, 2024
@pacocoursey Do I understand correctly that in v1.0 it's still not possible to disable the auto-select of the first item? Is it some sort of accessibility concern?
vinceflores commentedon Jun 6, 2024
Heres an example where only the CommandItem selected is highlighted on render
andrecasal commentedon Jul 2, 2024
If the component sits below the fold, the page will always scroll to the first selected item, which is a pain. Any way to disable any kind of selection on render would be much appreciated.
AMerkuri commentedon Sep 11, 2024
This solution preserves selected value and allows keyboard navigation.
<Command defaultValue={value} disablePointerSelection={true}>maerzhase commentedon Oct 18, 2024
would be cool to get an API for this.
selectFirstItem={false}would do the trick.Example where it comes in handy: Let's say you use the UI for a search input that can display some suggestions. You want to write into the input and submit the search query only OR you wanna select an item (via keyboard or mouse) and trigger the suggestion.
zachlankton commentedon Nov 14, 2024
Monkey Patch to the rescue for me:
Unsleeping commentedon Feb 11, 2025
This works fine, but
<CommandEmpty>is not available with this fix.Btw, I found a solution for this, i just remove hidden
<CommandItem/>to display<CommandEmpty/>ako-v commentedon Feb 25, 2025
This is the solution to the problem, is sets the
data-selectedandaria-selectedto true on the selected one. but we do not need to disabledisablePointerSelection. just set the defaultValue.if you want to disable the selection of the first item just set the default value to a non existing value, but not
undefined<Command defaultValue={"-"} >ryantbrown commentedon Mar 1, 2025
This worked for me
sirajtahra commentedon Apr 14, 2025
+1