Skip to content

Commit 13e6fab

Browse files
committed
fix: make "Search" nav item and "Search for query" separate
Trying to collapse them was causing more problems than it solved.
1 parent 3959303 commit 13e6fab

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

app/composables/useCommandPaletteCommands.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ export function useCommandPaletteCommands() {
8585
}
8686

8787
const trimmedQuery = computed(() => query.value.trim())
88-
const { globalCommands, viewDefinitions } = useCommandPaletteGlobalCommands({
89-
submitSearchQuery,
90-
})
88+
const { globalCommands, viewDefinitions } = useCommandPaletteGlobalCommands()
9189
const currentViewDefinition = computed(() =>
9290
view.value === 'root' ? null : viewDefinitions.value[view.value],
9391
)
@@ -126,13 +124,13 @@ export function useCommandPaletteCommands() {
126124
const trailingSearchCommand = computed<CommandPaletteCommand | null>(() => {
127125
if (view.value !== 'root' || !trimmedQuery.value) return null
128126

129-
const searchCommand = rootViewCommands.value.find(command => command.id === 'search')
130-
if (!searchCommand) return null
131-
132127
return {
133-
...searchCommand,
128+
id: 'search-query',
129+
group: 'actions' as const,
134130
label: t('command_palette.actions.search_for', { query: trimmedQuery.value }),
135-
keywords: [...searchCommand.keywords, trimmedQuery.value],
131+
keywords: [t('search.title_packages'), t('search.label'), trimmedQuery.value],
132+
iconClass: 'i-lucide:search',
133+
action: submitSearchQuery,
136134
}
137135
})
138136

app/composables/useCommandPaletteGlobalCommands.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import {
66
NPMX_DOCS_SITE,
77
} from '#shared/utils/constants'
88

9-
interface UseCommandPaletteGlobalCommandsOptions {
10-
submitSearchQuery: () => Promise<void>
11-
}
12-
139
type CommandPaletteSubview = Exclude<CommandPaletteView, 'root'>
1410

1511
interface CommandPaletteViewDefinition {
@@ -73,9 +69,7 @@ function withRootSearchLabel(command: CommandPaletteCommand, label: string): Com
7369
}
7470
}
7571

76-
export function useCommandPaletteGlobalCommands({
77-
submitSearchQuery,
78-
}: UseCommandPaletteGlobalCommandsOptions) {
72+
export function useCommandPaletteGlobalCommands() {
7973
const { locale, locales, setLocale, t } = useI18n()
8074
const route = useRoute()
8175
const colorMode = useColorMode()
@@ -219,7 +213,9 @@ export function useCommandPaletteGlobalCommands({
219213
label: t('command_palette.actions.search'),
220214
keywords: [t('search.title_packages'), t('search.label')],
221215
iconClass: 'i-lucide:search',
222-
action: submitSearchQuery,
216+
active: route.name === 'search',
217+
activeLabel: activeLabel(route.name === 'search', t('command_palette.here')),
218+
to: { name: 'search' },
223219
},
224220
{
225221
id: 'keyboard-shortcuts',

test/nuxt/composables/use-command-palette-commands.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ describe('useCommandPaletteCommands', () => {
336336
},
337337
})
338338

339-
expect(flatCommands.value.find(command => command.id === 'search')).toBeTruthy()
339+
expect(flatCommands.value.find(command => command.id === 'search-query')).toBeTruthy()
340340
expect(
341341
groupedCommands.value.find(group => group.id === 'versions')?.items.map(item => item.id),
342342
).toEqual(['version:3.4.2', 'version:3.5.0'])
@@ -378,8 +378,8 @@ describe('useCommandPaletteCommands', () => {
378378
query: 'webpack',
379379
})
380380

381-
expect(flatCommands.value.find(command => command.id === 'search')).toBeTruthy()
382-
expect(flatCommands.value.at(-1)?.id).toBe('search')
381+
expect(flatCommands.value.find(command => command.id === 'search-query')).toBeTruthy()
382+
expect(flatCommands.value.at(-1)?.id).toBe('search-query')
383383
expect(flatCommands.value.at(-1)?.label).toBe('Search for "webpack"')
384384

385385
wrapper.unmount()

0 commit comments

Comments
 (0)