Skip to content

Conversation

Ismaele-silla
Copy link

@Ismaele-silla Ismaele-silla commented Oct 9, 2025

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Adds an option to preserve the original order of groups in the CommandPalette component.
Currently, groups are always ordered by the top-scoring item within each group (based on Fuse search results). This change allows developers to keep their own predefined group order instead.

Motivation

Some applications require explicit control over how result groups are presented.
For example, on a content-driven website, you may want users to see their own content first, global content next, and other users’ content last. The current behavior forces all groups to be reordered by search relevance, which breaks this intended priority.

Implementation

  • Adds a new prop (preserveGroupOrder) to the CommandPalette component.
  • Maintains existing code and behavior when the prop is not set.
  • Updated test accordingly
  • API was automatically updated in the Docs

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@github-actions github-actions bot added the v4 #4488 label Oct 9, 2025
Copy link

pkg-pr-new bot commented Oct 9, 2025

npm i https://pkg.pr.new/@nuxt/ui@5197

commit: c64d037

@benjamincanac
Copy link
Member

The CommandPalette component is powered by Fuse to provide the best matching results first which should stay the default. We should add a prop to change this behavior, something like preserveOrder? πŸ€”

@benjamincanac benjamincanac marked this pull request as draft October 10, 2025 12:13
@Ismaele-silla
Copy link
Author

The CommandPalette component is powered by Fuse to provide the best matching results first which should stay the default. We should add a prop to change this behavior, something like preserveOrder? πŸ€”

That's a good point, and I didn't think about ordering groups by best matching result. Looking at the original code, though, I can see that Fuse results are only used to order items within groups but not the groups themselves.
I'll get back to you with a fix that uses Fuse to order groups as well, and we can also add a preserveGroupOrder prop for my use case (if you agree it might be useful for other developers).

@benjamincanac
Copy link
Member

Yes it does, you can see this clearly by using the search on ui.nuxt.com! Groups are recomputed from fuse results: https://github.com/nuxt/ui/blob/v4/src/runtime/components/CommandPalette.vue#L287

@Ismaele-silla Ismaele-silla force-pushed the fix/preserve-command-palette-group-order branch from 76bee9a to 93b3e73 Compare October 12, 2025 05:43
@Ismaele-silla Ismaele-silla changed the title fix(CommandPalette): preserve group order in search results feat(CommandPalette): preserve group order in search results Oct 12, 2025
@Ismaele-silla
Copy link
Author

Ismaele-silla commented Oct 12, 2025

Yes it does, you can see this clearly by using the search on ui.nuxt.com! Groups are recomputed from fuse results: https://github.com/nuxt/ui/blob/v4/src/runtime/components/CommandPalette.vue#L287

Sorry, my bad. I took more time to read the code and now have a better understanding of what it does and how it works.
I changed the PR and turned it into a feature. I also tried to describe my use case as clearly as I could.

A new prop, preserveGroupOrder, allows you to decide whether the order of groups defined in the props is preserved or not.
I did my best to make the code readable and performant. I hope everything is okay!

PS: you can test the difference in the playground by searching for "Ad" in the command palette component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v4 #4488

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants