Utilisation
Le composant DashboardSearch étend le composant CommandPalette, de sorte que vous pouvez passer n'importe quelle propriété telle que icon, placeholder, etc.
Utilisez-le à l'intérieur de l'emplacement par défaut du composant DashboardGroup:
<template>
<UDashboardGroup>
<UDashboardSidebar>
<UDashboardSearchButton />
</UDashboardSidebar>
<UDashboardSearch />
<slot />
</UDashboardGroup>
</template>
v-model:open.Raccourci
Utilisez la prop shortcut pour modifier le raccourci utilisé dans defineShortcuts pour ouvrir le composant ContentSearch. Defaults à meta_k (: kbd{value="meta"}: kbd{value="K"}).
<template>
<UDashboardSearch
v-model:search-term="searchTerm"
shortcut="meta_k"
:groups="groups"
:fuse="{ resultLimit: 42 }"
/>
</template>
Couleur Mode
Par défaut, un groupe de commandes sera ajouté à la palette de commandes afin que vous puissiez basculer entre le mode clair et sombre. Cela ne prendra effet que si le colorMode n'est pas forcé dans une page spécifique, ce qui peut être réalisé via definePageMeta:
<script setup lang="ts">
definePageMeta({
colorMode: 'dark'
})
</script>
Vous pouvez désactiver ce comportement en définissant la prop color-mode sur false:
<template>
<UDashboardSearch
v-model:search-term="searchTerm"
:color-mode="false"
:groups="groups"
:fuse="{ resultLimit: 42 }"
/>
</template>
api
Projets
| Prop | Default | Type |
|---|---|---|
size | 'md' | "sm" | "md" | "xs" | "lg" | "xl" |
close | true | boolean | Omit<ButtonProps, LinkPropsKeys> Display a close button in the input (useful when inside a Modal for example).
|
input | true | boolean | Omit<InputProps<AcceptableValue, ModelModifiers>, "modelValue" | "defaultValue"> Configure the input or hide it with |
shortcut | 'meta_k' | stringKeyboard shortcut to open the search (used by |
fuse | { fuseOptions: { ignoreLocation: true, useTokenSearch: true, threshold: 0.1, keys: ['label', 'description', 'suffix'] }, resultLimit: 12, matchAllWhenSearchEmpty: true } | UseFuseOptions<CommandPaletteItem>Options for useFuse passed to the CommandPalette. |
searchDelay | 100 | numberDelay (in milliseconds) before the search term is passed to Fuse (debounced).
Useful for large datasets where running fuzzy search on every keystroke is the bottleneck — the input stays responsive while Fuse only re-runs after typing settles.
Set to |
colorMode | true | boolean When |
title | string | |
transition | true | boolean Animate the modal when opening or closing. |
description | string | |
overlay | true | boolean Render an overlay behind the modal. |
content | DialogContentProps & Partial<EmitsToProps<DialogContentImplEmits>>The content of the modal. | |
dismissible | true | boolean When |
fullscreen | false | boolean When |
modal | boolean The modality of the dialog When set to | |
portal | true | string | false | true | HTMLElementRender the modal in a portal. |
unmountOnHide | true | boolean When set to |
icon | appConfig.ui.icons.search | anyThe icon displayed in the input. Set to |
autofocus | true | boolean Automatically focus the input when component is mounted. |
disabled | boolean When | |
trailingIcon | appConfig.ui.icons.search | anyThe icon displayed on the right side of the input. |
loading | boolean When | |
loadingIcon | appConfig.ui.icons.loading | anyThe icon when the |
selectedIcon | appConfig.ui.icons.check | anyThe icon displayed when an item is selected. |
childrenIcon | appConfig.ui.icons.chevronRight | anyThe icon displayed when an item has children. |
placeholder | t('commandPalette.placeholder') | stringThe placeholder text for the input. |
closeIcon | appConfig.ui.icons.close | anyThe icon displayed in the close button. |
back | true | boolean | Omit<ButtonProps, LinkPropsKeys> Display a button to navigate back in history.
|
backIcon | appConfig.ui.icons.arrowLeft | anyThe icon displayed in the back button. |
highlightOnHover | boolean When | |
labelKey | 'label' | stringThe key used to get the label from the item. |
descriptionKey | 'description' | stringThe key used to get the description from the item. |
preserveGroupOrder | false | boolean Whether to preserve the order of groups as defined in the |
virtualize | false | boolean | { overscan?: number ; estimateSize?: number | ((index: number) => number) | undefined; } | undefinedEnable virtualization for large lists. Note: when enabled, all groups are flattened into a single list due to a limitation of Reka UI (https://github.com/unovue/reka-ui/issues/1885). |
groups | CommandPaletteGroup<CommandPaletteItem>[] | |
open | false | boolean |
searchTerm | '' | string |
ui | { modal?: SlotClass; input?: SlotClass; } & { root?: SlotClass; input?: SlotClass; close?: SlotClass; back?: SlotClass; content?: SlotClass; footer?: SlotClass; viewport?: SlotClass; group?: SlotClass; empty?: SlotClass; label?: SlotClass; item?: SlotClass; itemLeadingIcon?: SlotClass; itemLeadingAvatar?: SlotClass; itemLeadingAvatarSize?: SlotClass; itemLeadingChip?: SlotClass; itemLeadingChipSize?: SlotClass; itemTrailing?: SlotClass; itemTrailingIcon?: SlotClass; itemTrailingHighlightedIcon?: SlotClass; itemTrailingKbds?: SlotClass; itemTrailingKbdsSize?: SlotClass; itemWrapper?: SlotClass; itemLabel?: SlotClass; itemLabelBase?: SlotClass; itemLabelPrefix?: SlotClass; itemLabelSuffix?: SlotClass; itemDescription?: SlotClass; } |
Slots électroniques
| Slot | Type |
|---|---|
empty | { searchTerm: string; } |
footer | { ui: object; } |
back | { ui: object; } |
close | { ui: object; } |
item | { item: CommandPaletteItem; index: number; ui: object; } |
item-leading | { item: CommandPaletteItem; index: number; ui: object; } |
item-label | { item: CommandPaletteItem; index: number; ui: object; } |
item-description | { item: CommandPaletteItem; index: number; ui: object; } |
item-trailing | { item: CommandPaletteItem; index: number; ui: object; } |
group-label | { group: CommandPaletteGroup<CommandPaletteItem>; label: string; ui: object; } |
content | { close: () => void; } |
Emis
| Event | Type |
|---|---|
update:open | [value: boolean] |
update:searchTerm | [value: string] |
Exposé
Lorsque vous accédez au composant via une référence de modèle, vous pouvez utiliser les éléments suivants:
| nom | type |
|---|---|
commandPaletteRefx{lang="ts-type"} | Ref<InstanceType<typeof UCommandPalette> | null>x{lang="ts-type"} |
Thème
export default defineAppConfig({
ui: {
dashboardSearch: {
slots: {
modal: '',
input: ''
},
variants: {
fullscreen: {
false: {
modal: 'sm:max-w-3xl h-full sm:h-[28rem]'
}
},
size: {
xs: {},
sm: {},
md: {},
lg: {},
xl: {}
}
},
defaultVariants: {
size: 'md'
}
}
}
})import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
dashboardSearch: {
slots: {
modal: '',
input: ''
},
variants: {
fullscreen: {
false: {
modal: 'sm:max-w-3xl h-full sm:h-[28rem]'
}
},
size: {
xs: {},
sm: {},
md: {},
lg: {},
xl: {}
}
},
defaultVariants: {
size: 'md'
}
}
}
})
]
})