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'button'any

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

iconappConfig.ui.icons.searchany

The icon displayed in the button.

labelt('contentSearchButton.label') string

The label displayed in the button.

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

The color of the button.

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

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

collapsedtrueboolean

Whether the button is collapsed.

tooltipfalseboolean | 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.

autofocus false | true | "true" | "false"
disabledboolean
name string
type'button' "reset" | "submit" | "button"

The type of the button when not a link.

downloadany
hreflang string
media string
ping string
target null | string & {} | "_blank" | "_parent" | "_self" | "_top"

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

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

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

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.

activeColor "error" | "neutral" | "primary" | "secondary" | "success" | "info" | "warning"
activeVariant "solid" | "outline" | "soft" | "subtle" | "ghost" | "link"
size'md' "xs" | "sm" | "md" | "lg" | "xl"
squareboolean

Render the button with equal padding on all sides.

blockboolean

Render the button full width.

loadingAutoboolean

Set loading state automatically based on the @click promise state

avatar AvatarProps

Display an avatar on the left side.

leadingboolean

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

leadingIconany

Display an icon on the left side.

trailingboolean

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

trailingIconany

Display an icon on the right side.

loadingboolean

When true, the loading icon will be displayed.

loadingIconappConfig.ui.icons.loadingany

The icon when the loading prop is true.

ui { base?: ClassNameValue; label?: 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{ 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; }; }
default{ 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; }; }
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: '',
        label: '',
        trailing: 'hidden lg:flex items-center gap-0.5 ms-auto'
      },
      variants: {
        collapsed: {
          true: {
            label: 'hidden',
            trailing: 'lg:hidden'
          }
        }
      }
    }
  }
})
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: '',
            label: '',
            trailing: 'hidden lg:flex items-center gap-0.5 ms-auto'
          },
          variants: {
            collapsed: {
              true: {
                label: 'hidden',
                trailing: 'lg:hidden'
              }
            }
          }
        }
      }
    })
  ]
})

Changelog

3e72b — fix: hide label and trailing with css when collapsed

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

5b177 — feat: extend native HTML attributes (#5348)

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