Open arvinpoddar opened 2 months ago
A workaround is to make the Command component controlled and set the selected item yourself when the items change.
A workaround is to make the Command component controlled and set the selected item yourself when the items change.
Yep, ultimately the workaround we implemented was something like this, but it feels hacky to have to have a side effect on state to accomplish this. Ideally, the behavior should come baked in with Command if the user is not using it as a controlled component.
When using a deferred value to make a query (closely referencing the
useDeferredValue
docs example: https://react.dev/reference/react/useDeferredValue#usage), the first item in the list is not always highlighted when the query results update. Only after additional query refinement will the first result become selected.We do get the desired behavior if we remove the
shouldFilter={false}
, but the auto-selection behavior should still work if you're relying on external filtering behavior.Reproduction CodeSandbox: https://codesandbox.io/p/devbox/cmdk-suspense-9jth8l
Reproduction Video:
https://github.com/pacocoursey/cmdk/assets/8345645/65fe6144-ca2f-4e7f-b85c-755f6fade837
Thank you!