106k
New

快捷键 Kbd

用于显示来自键盘的文本用户输入。

Ctrl+B
import { Kbd, KbdGroup } from "@/components/ui/kbd"

export function KbdDemo() {

安装

pnpm dlx shadcn@latest add kbd

使用

import { Kbd } from "@/components/ui/kbd"
<Kbd>Ctrl</Kbd>

示例

分组

使用 KbdGroup 组件将键盘按键组合在一起。

Use Ctrl + BCtrl + K to open the command palette

import { Kbd, KbdGroup } from "@/components/ui/kbd"

export function KbdGroupExample() {

按钮

Button 组件内使用 Kbd 组件以在按钮内部显示键盘按键。

import { Button } from "@/components/ui/button"
import { Kbd } from "@/components/ui/kbd"

提示

你可以在 Tooltip 组件内使用 Kbd 组件,以显示带有键盘按键的提示。

import { Button } from "@/components/ui/button"
import { ButtonGroup } from "@/components/ui/button-group"
import { Kbd, KbdGroup } from "@/components/ui/kbd"

输入组

你可以在 InputGroupAddon 组件内使用 Kbd 组件,以在输入组中显示键盘按键。

K
import {
  InputGroup,
  InputGroupAddon,

API 参考

Kbd

使用 Kbd 组件显示键盘按键。

属性类型默认值
classNamestring``
<Kbd>Ctrl</Kbd>

KbdGroup

使用 KbdGroup 组件将多个 Kbd 组件组合在一起。

属性类型默认值
classNamestring``
<KbdGroup>
  <Kbd>Ctrl</Kbd>
  <Kbd>B</Kbd>
</KbdGroup>