ContentSearch
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.
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).
<template>
<UApp>
<ClientOnly>
<LazyUContentSearch
v-model:search-term="searchTerm"
shortcut="meta_k"
:files="files"
:navigation="navigation"
:fuse="{ resultLimit: 42 }"
/>
</ClientOnly>
</UApp>
</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:
<script setup lang="ts">
definePageMeta({
colorMode: 'dark'
})
</script>
You can disable this behavior by setting the color-mode prop to false:
<template>
<UApp>
<ClientOnly>
<LazyUContentSearch
v-model:search-term="searchTerm"
:color-mode="false"
:files="files"
:navigation="navigation"
:fuse="{ resultLimit: 42 }"
/>
</ClientOnly>
</UApp>
</template>
Examples
Within app.vue
Use the ContentSearch component in your app.vue or in a layout:
<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: '/docs/getting-started'
}, {
label: 'Components',
icon: 'i-lucide-box',
to: '/docs/components'
}, {
label: 'Showcase',
icon: 'i-lucide-presentation',
to: '/showcase'
}]
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>
ContentSearch component in a ClientOnly component so it's not rendered on the server.API
Props
| Prop | Default | Type |
|---|---|---|
icon |
|
The icon displayed in the input. |
placeholder |
|
The placeholder text for the input. |
autofocus |
|
Automatically focus the input when component is mounted. |
loading |
When | |
loadingIcon |
|
The icon when the |
close |
|
Display a close button in the input (useful when inside a Modal for example).
|
closeIcon |
|
The icon displayed in the close button. |
shortcut |
|
Keyboard shortcut to open the search (used by |
links |
Links group displayed as the first group in the command palette.
| |
navigation |
| |
groups |
Custom groups displayed between navigation and color mode group. | |
files |
| |
fuse |
|
Options for useFuse passed to the CommandPalette. |
colorMode |
|
When |
title |
| |
description |
| |
overlay |
|
Render an overlay behind the modal. |
transition |
|
Animate the modal when opening or closing. |
content |
The content of the modal.
| |
dismissible |
|
When |
fullscreen |
|
When |
modal |
The modality of the dialog When set to | |
portal |
|
Render the modal in a portal. |
searchTerm |
|
|
ui |
|
Slots
| Slot | Type |
|---|---|
empty |
|
footer |
|
back |
|
close |
|
item |
|
item-leading |
|
item-label |
|
item-trailing |
|
content |
|
Emits
| Event | Type |
|---|---|
update:searchTerm |
|
Theme
export default defineAppConfig({
ui: {
contentSearch: {
slots: {
modal: '',
input: '[&>input]:text-base/5'
},
variants: {
fullscreen: {
false: {
modal: 'sm:max-w-3xl sm:h-[28rem]'
}
}
}
}
}
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
contentSearch: {
slots: {
modal: '',
input: '[&>input]:text-base/5'
},
variants: {
fullscreen: {
false: {
modal: 'sm:max-w-3xl sm:h-[28rem]'
}
}
}
}
}
})
]
})