111k

Command

用于搜索和快速操作的命令菜单。

import {
  Command,
  CommandEmpty,

关于

<Command /> 组件基于 Dipcmdk 组件。

安装

pnpm dlx shadcn@latest add command

用法

import {
  Command,
  CommandDialog,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
  CommandSeparator,
  CommandShortcut,
} from "@/components/ui/command"
<Command className="max-w-sm rounded-lg border">
  <CommandInput placeholder="Type a command or search..." />
  <CommandList>
    <CommandEmpty>No results found.</CommandEmpty>
    <CommandGroup heading="Suggestions">
      <CommandItem>Calendar</CommandItem>
      <CommandItem>Search Emoji</CommandItem>
      <CommandItem>Calculator</CommandItem>
    </CommandGroup>
    <CommandSeparator />
    <CommandGroup heading="Settings">
      <CommandItem>Profile</CommandItem>
      <CommandItem>Billing</CommandItem>
      <CommandItem>Settings</CommandItem>
    </CommandGroup>
  </CommandList>
</Command>

示例

基础

一个位于对话框中的简单命令菜单。

Command Palette

Search for a command to run...

"use client"

import * as React from "react"

快捷键

Command Palette

Search for a command to run...

"use client"

import * as React from "react"

分组

一个包含分组、图标和分隔线的命令菜单。

Command Palette

Search for a command to run...

"use client"

import * as React from "react"

可滚动

一个包含多个项目、可滚动的命令菜单。

Command Palette

Search for a command to run...

"use client"

import * as React from "react"

RTL

要在 shadcn/ui 中启用 RTL 支持,请参见 RTL 配置指南

"use client"

import * as React from "react"

API 参考

更多信息请参见 cmdk 文档。