DashboardSearch

A ready to use CommandPalette to add to your dashboard.

Usage

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

Use it inside the default slot of the DashboardGroup component:

layouts/dashboard.vue
<template>
  <UDashboardGroup>
    <UDashboardSidebar>
      <UDashboardSearchButton />
    </UDashboardSidebar>

    <UDashboardSearch />

    <slot />
  </UDashboardGroup>
</template>
You can open the CommandPalette by pressing K, by using the DashboardSearchButton component or by using a v-model:open directive.

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>
  <UDashboardSearch
    v-model:search-term="searchTerm"
    shortcut="meta_k"
    :groups="groups"
    :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>
  <UDashboardSearch
    v-model:search-term="searchTerm"
    :color-mode="false"
    :groups="groups"
    :fuse="{ resultLimit: 42 }"
  />
</template>

API

Props

Prop Default Type
iconappConfig.ui.icons.search string | object

The icon displayed in the input.

placeholdert('commandPalette.placeholder') string

The placeholder text for the input.

autofocustrueboolean

Automatically focus the input when component is mounted.

loadingboolean

When true, the loading icon will be displayed.

loadingIconappConfig.ui.icons.loading string | object

The icon when the loading prop is true.

closetrueboolean | Partial<ButtonProps>

Display a close button in the input (useful when inside a Modal for example). { size: 'md', color: 'neutral', variant: 'ghost' }

closeIconappConfig.ui.icons.close string | object

The icon displayed in the close button.

shortcut'meta_k' string

Keyboard shortcut to open the search (used by defineShortcuts)

groups CommandPaletteGroup<CommandPaletteItem>[]
fuse{} UseFuseOptions<CommandPaletteItem>

Options for useFuse passed to the CommandPalette.

colorModetrueboolean

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

title string
description string
overlaytrueboolean

Render an overlay behind the modal.

transitiontrueboolean

Animate the modal when opening or closing.

content DialogContentProps & Partial<EmitsToProps<DialogContentImplEmits>>

The content of the modal.

dismissibletrueboolean

When false, the modal will not close when clicking outside or pressing escape.

fullscreenfalseboolean

When true, the modal will take up the full screen.

modalboolean

The modality of the dialog When set to true,
interaction with outside elements will be disabled and only dialog content will be visible to screen readers.

portaltrue string | false | true | HTMLElement

Render the modal in a portal.

openfalseboolean
searchTerm'' string
ui { modal?: ClassNameValue; input?: ClassNameValue; } & { root?: ClassNameValue; input?: ClassNameValue; close?: ClassNameValue; back?: ClassNameValue; content?: ClassNameValue; footer?: ClassNameValue; viewport?: ClassNameValue; group?: ClassNameValue; empty?: ClassNameValue; label?: ClassNameValue; item?: ClassNameValue; itemLeadingIcon?: ClassNameValue; itemLeadingAvatar?: ClassNameValue; itemLeadingAvatarSize?: ClassNameValue; itemLeadingChip?: ClassNameValue; itemLeadingChipSize?: ClassNameValue; itemTrailing?: ClassNameValue; itemTrailingIcon?: ClassNameValue; itemTrailingHighlightedIcon?: ClassNameValue; itemTrailingKbds?: ClassNameValue; itemTrailingKbdsSize?: ClassNameValue; itemWrapper?: ClassNameValue; itemLabel?: ClassNameValue; itemDescription?: ClassNameValue; itemLabelBase?: ClassNameValue; itemLabelPrefix?: ClassNameValue; itemLabelSuffix?: ClassNameValue; }

Slots

Slot Type
empty{ searchTerm?: string | undefined; }
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; }
content{ close: () => void; }

Emits

Event Type
update:open[value: boolean]
update:searchTerm[value: string]

Expose

When accessing the component via a template ref, you can use the following:

NameType
commandPaletteRefRef<InstanceType<typeof UCommandPalette> | null>

Theme

app.config.ts
export default defineAppConfig({
  ui: {
    dashboardSearch: {
      slots: {
        modal: '',
        input: '[&>input]:text-base/5'
      },
      variants: {
        fullscreen: {
          false: {
            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({
      ui: {
        dashboardSearch: {
          slots: {
            modal: '',
            input: '[&>input]:text-base/5'
          },
          variants: {
            fullscreen: {
              false: {
                modal: 'sm:max-w-3xl sm:h-[28rem]'
              }
            }
          }
        }
      }
    })
  ]
})

Changelog

dd81d — feat: add data-slot attributes (#5447)

fce2d — fix!: consistent exposed refs (#5385)

63c0a — feat: expose ui in slot props where used (#5207)

095a0 — fix: proxy modal props to support fullscreen

3173b — fix: proxySlots reactivity (#4969)

61b60 — feat: allow passing a component instead of a name (#4766)

946c2 — fix: make ui.modal work

5cb65 — feat: import @nuxt/ui-pro components