A ready to use CommandPalette to add to your documentation.
This component is only available when the @nuxt/content module is installed.

Usage

The ContentSearch component extends the CommandPalette component, so you can pass any property such as icon, placeholder, etc.

Use the files and navigation props with the files and navigation values you fetched using the queryCollectionSearchSections and queryCollectionNavigation composables from @nuxt/content.

You can open the CommandPalette by pressing K, by using the ContentSearchButton component or by using the useContentSearch composable: const { open } = useContentSearch().

Shortcut

Use the shortcut prop to change the shortcut used in defineShortcuts to open the ContentSearch component. Defaults to meta_k ( K).

app.vue
<template>
  <UContentSearch
    v-model:search-term="searchTerm"
    shortcut="meta_k"
    :files="files"
    :navigation="navigation"
    :fuse="{ resultLimit: 42 }"
  />
</template>

Color Mode

By default, a group of commands will be added to the command palette so you can switch between light and dark mode. This will only take effect if the colorMode is not forced in a specific page which can be achieved through definePageMeta:

pages/index.vue
<script setup lang="ts">
definePageMeta({
  colorMode: 'dark'
})
</script>

You can disable this behavior by setting the color-mode prop to false:

app.vue
<template>
  <UContentSearch
    v-model:search-term="searchTerm"
    :color-mode="false"
    :files="files"
    :navigation="navigation"
    :fuse="{ resultLimit: 42 }"
  />
</template>

Examples

Within app.vue

Use the ContentSearch component in your app.vue or in a layout:

app.vue
<script setup lang="ts">
const { data: navigation } = await useAsyncData('navigation', () => queryCollectionNavigation('content'))
const { data: files } = useLazyAsyncData('search', () => queryCollectionSearchSections('content'), {
  server: false
})

const links = [{
  label: 'Docs',
  icon: 'i-lucide-book',
  to: '/getting-started'
}, {
  label: 'Components',
  icon: 'i-lucide-box',
  to: '/components'
}, {
  label: 'Roadmap',
  icon: 'i-lucide-chart-no-axes-gantt',
  to: '/roadmap'
}]

const searchTerm = ref('')
</script>

<template>
  <UApp>
    <ClientOnly>
      <LazyUContentSearch
        v-model:search-term="searchTerm"
        :files="files"
        shortcut="meta_k"
        :navigation="navigation"
        :links="links"
        :fuse="{ resultLimit: 42 }"
      />
    </ClientOnly>
  </UApp>
</template>
It is recommended to wrap the ContentSearch component in a ClientOnly component so it's not rendered on the server.

API

Props

Prop Default Type
searchTerm

string

icon

appConfig.ui.icons.search

string

Icon for the search input.

placeholder

'Type a command or search...'

string

Placeholder for the search input.

loading

boolean

When true, the loading icon will be displayed.

loadingIcon

appConfig.ui.icons.loading

string

The icon when the loading prop is true.

shortcut

'meta_k'

string

Keyboard shortcut to open the search (used by defineShortcuts)

links

ContentSearchLink[]

Links group displayed as the first group in the command palette.

navigation

ContentNavigationItem[]

groups

CommandPaletteGroup<ContentSearchItem>[]

Custom groups displayed between navigation and color mode group.

files

ContentSearchFile[]

fuse

{ fuseOptions: { includeMatches: true } }

UseFuseOptions<ContentSearchLink>

Options for useFuse passed to the CommandPalette.

colorMode

true

boolean

When true, the theme command will be added to the groups.

ui

Partial<{ modal: string; }>

Slots

Slot Type
empty

{ searchTerm?: string | undefined; }

close

{ ui: any; }

item

{ item: ContentSearchItem; index: number; }

item-leading

{ item: ContentSearchItem; index: number; }

item-label

{ item: ContentSearchItem; index: number; }

item-trailing

{ item: ContentSearchItem; index: number; }

Emits

Event Type
update:searchTerm

[value: string | undefined]

Theme

app.config.ts
export default defineAppConfig({
  uiPro: {
    contentSearch: {
      slots: {
        modal: 'sm:max-w-3xl sm:h-[28rem]'
      }
    }
  }
})
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'

export default defineConfig({
  plugins: [
    vue(),
    ui({
      uiPro: {
        contentSearch: {
          slots: {
            modal: 'sm:max-w-3xl sm:h-[28rem]'
          }
        }
      }
    })
  ]
})