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
Programmatically set selection without affected input value #243
I would like to implement the PageUp/PageDown functionality which, but it doesn't look like the library supports setting the Selection programmatically - which renders the functionality of PageUp/PageDown useless as when you press up/down arrow, it scrolls back up because the selection remains the same.
I can see that Home/End works natively with the library and moves the selection.
I wish the library exposed the internal API and gave me the possibility to programmatically set the selection.
cmdk.mov
Thanks!
Reacted by masewo, updbqn, Mieszko Sabo, John Carmack, Riva Madan, enta and Allie Falco
I would like to integrate the item selection with tanstack router <Link> preloading to prefetch some data before selecting the command item.
We currently partially fixed this by using a ref on the <Link> component to manage the onSelect (navigating) & onFocus (preloading) but we are still missing preloading whenever the user navigate with the arrow keys.
I would also like to be able to programmatically set selection. For my use case, I want "tab" keydown to move to a specific special item within our list of items.
I saw that internally it is set via store.setState('value', value || undefined), if we could wrap a function around this and expose it, that'd be great.
I've seen several issues/feature requests that could have reasonable workarounds if the store was just exposed somehow. I understand the reluctance and I think that it would go without saying that directly messing with the store requires a "use at your own risk" caveat, but nevertheless such escape hatches can be extremely useful when you are just trying to ship code.
You can externally control the . Just set its value prop and the Command.Item having this value is selected. However, you probably lose some internal things (e.g., auto scrolling) ….at least that is what I am just struggling with ;)
You can externally control the . Just set its value prop and the Command.Item having this value is selected. However, you probably lose some internal things (e.g., auto scrolling) ….at least that is what I am just struggling with ;)
Exactly..did you figure this out? or did u implement auto scroll yourself? @came
Activity
DjordyKoert commentedon May 29, 2024
I think my question/feature is related to this.
(We use the shadcn/ui Command component for this)
I would like to integrate the item selection with tanstack router
<Link>preloading to prefetch some data before selecting the command item.We currently partially fixed this by using a ref on the
<Link>component to manage theonSelect(navigating) & onFocus (preloading) but we are still missing preloading whenever the user navigate with the arrow keys.rivamadan commentedon Oct 7, 2024
I would also like to be able to programmatically set selection. For my use case, I want "tab" keydown to move to a specific special item within our list of items.
I saw that internally it is set via
store.setState('value', value || undefined), if we could wrap a function around this and expose it, that'd be great.jayalfredprufrock commentedon Oct 10, 2024
I've seen several issues/feature requests that could have reasonable workarounds if the store was just exposed somehow. I understand the reluctance and I think that it would go without saying that directly messing with the store requires a "use at your own risk" caveat, but nevertheless such escape hatches can be extremely useful when you are just trying to ship code.
came commentedon Dec 11, 2024
You can externally control the . Just set its value prop and the Command.Item having this value is selected. However, you probably lose some internal things (e.g., auto scrolling) ….at least that is what I am just struggling with ;)
glekner commentedon Jan 23, 2025
Exactly..did you figure this out? or did u implement auto scroll yourself? @came