Skip to content

fix(cmdk): Omit empty groups and reset scroll on query change#112325

Merged
JonasBa merged 1 commit intojb/cmdk/jsx-pocfrom
jb/cmdk/async-action
Apr 9, 2026
Merged

fix(cmdk): Omit empty groups and reset scroll on query change#112325
JonasBa merged 1 commit intojb/cmdk/jsx-pocfrom
jb/cmdk/async-action

Conversation

@JonasBa
Copy link
Copy Markdown
Member

@JonasBa JonasBa commented Apr 7, 2026

Two small fixes for the JSX-powered command palette.

Empty groups are now omitted from the list. A CMDKGroup that renders no children ends up with zero registered nodes in the collection. In browse mode, flattenActions was treating such nodes as leaf actions and showing them. These are headless section headers with nothing to show — they should be invisible. The fix skips any node that has no children and no executable action (to / onAction).

Scroll resets to the top when the query changes. Typing a new search query now scrolls the results list back to the top. The tricky part: ResultsList is not the actual scroll element — ListBox creates its own inner div that it hands to TanStack Virtual as the scroll container. The fix adds a scrollContainerRef prop to ListBox that gets merged into that inner container's refs, then wires it up in the onChange handler.

Stacked on #112262.

Empty CMDKGroups (no registered children) were appearing as clickable
action items in browse mode. Filter them out in flattenActions so only
groups with children or executable actions are shown.

Also reset the results list scroll position to the top whenever the
search query changes. The actual scroll element is the inner virtualizer
container inside ListBox, not the outer ResultsList wrapper, so expose
a scrollContainerRef prop on ListBox and wire it up in CommandPalette's
onChange handler.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 7, 2026
@JonasBa JonasBa marked this pull request as ready for review April 7, 2026 00:41
@JonasBa JonasBa requested a review from a team as a code owner April 7, 2026 00:41
@JonasBa JonasBa merged commit 9d70bc8 into jb/cmdk/jsx-poc Apr 9, 2026
63 of 64 checks passed
@JonasBa JonasBa deleted the jb/cmdk/async-action branch April 9, 2026 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants