ContentSearchButton

ButtonGitHub
A pre-styled Button to open the ContentSearch modal.
This component is only available when the @nuxt/content module is installed.

Usage

The ContentSearchButton component is used to open the ContentSearch modal.

<template>
  <UContentSearchButton />
</template>

It extends the Button component, so you can pass any property such as color, variant, size, etc.

<template>
  <UContentSearchButton variant="subtle" />
</template>
The button defaults to color="neutral" and variant="outline" when not collapsed, variant="ghost" when collapsed.

Collapsed

Use the collapsed prop to show the button's label and kbds. Defaults to true.

<template>
  <UContentSearchButton :collapsed="false" />
</template>

Kbds

Use the kbds prop to display keyboard keys in the button. Defaults to ['meta', 'K'] to match the default shortcut of the ContentSearch component.

<template>
  <UContentSearchButton :collapsed="false" :kbds="['alt', 'O']" />
</template>

API

Props

Prop Default Type
as

any

The element or component this component should render as when not a link.

icon

appConfig.ui.icons.search

string | object

The icon displayed in the button.

label

t('contentSearchButton.label')

string

The label displayed in the button.

color

'neutral'

The color of the button.

variant

The variant of the button. Defaults to 'outline' when not collapsed, 'ghost' when collapsed.

collapsed

true

boolean

Whether the button is collapsed.

tooltip

false

boolean | TooltipProps

Display a tooltip on the button when is collapsed with the button label. This has priority over the global tooltip prop.

kbds

["meta", "k"]

(string | undefined)[] | KbdProps[]

The keyboard keys to display in the button. { variant: 'subtle' }

to

string | RouteLocationAsRelativeGeneric | RouteLocationAsPathGeneric

Route Location the link should navigate to when clicked on.

target

null | "_blank" | "_parent" | "_self" | "_top" | string & {}

Where to display the linked URL, as the name for a browsing context.

trailingSlash

"append" | "remove"

An option to either add or remove trailing slashes in the href for this specific link. Overrides the global trailingSlash option if provided.

autofocus
disabled

boolean

form

string

formaction

string

formenctype

string

formmethod

string

formnovalidate

false | true | "true" | "false"

formtarget

string

name

string

type

'button'

"reset" | "submit" | "button"

The type of the button when not a link.

value

string | number | readonly string[]

download

any

hreflang

string

media

string

ping

string

referrerpolicy

"" | "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url"

active

boolean

Force the link to be active independent of the current route.

activeColor

"error" | "neutral" | "primary" | "secondary" | "success" | "info" | "warning"

activeVariant

"solid" | "outline" | "soft" | "subtle" | "ghost" | "link"

size

'md'

"xs" | "sm" | "md" | "lg" | "xl"

square

boolean

Render the button with equal padding on all sides.

block

boolean

Render the button full width.

loadingAuto

boolean

Set loading state automatically based on the @click promise state

avatar

AvatarProps

Display an avatar on the left side.

leading

boolean

When true, the icon will be displayed on the left side.

leadingIcon

string | object

Display an icon on the left side.

trailing

boolean

When true, the icon will be displayed on the right side.

trailingIcon

string | object

Display an icon on the right side.

loading

boolean

When true, the loading icon will be displayed.

loadingIcon

appConfig.ui.icons.loading

string | object

The icon when the loading prop is true.

ui

{ base?: ClassNameValue; trailing?: ClassNameValue; } & { base?: ClassNameValue; label?: ClassNameValue; leadingIcon?: ClassNameValue; leadingAvatar?: ClassNameValue; leadingAvatarSize?: ClassNameValue; trailingIcon?: ClassNameValue; }

This component also supports all native <button> HTML attributes.

Slots

Slot Type
leading
default
trailing

{ ui: { base: (props?: Record<string, any> | undefined) => string; label: (props?: Record<string, any> | undefined) => string; leadingIcon: (props?: Record<string, any> | undefined) => string; leadingAvatar: (props?: Record<string, any> | undefined) => string; leadingAvatarSize: (props?: Record<string, any> | undefined) => string; trailingIcon: (props?: Record<string, any> | undefined) => string; }; }

Theme

app.config.ts
export default defineAppConfig({
  ui: {
    contentSearchButton: {
      slots: {
        base: '',
        trailing: 'hidden lg:flex items-center gap-0.5 ms-auto'
      }
    }
  }
})
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: {
        contentSearchButton: {
          slots: {
            base: '',
            trailing: 'hidden lg:flex items-center gap-0.5 ms-auto'
          }
        }
      }
    })
  ]
})

Changelog

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

3173b — fix: proxySlots reactivity (#4969)

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

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