import { Kbd } from "@chakra-ui/react"
export const KbdBasic = () => {
return <Kbd>Shift + Tab</Kbd>
}
Anatomy
import { Kbd } from '@chakra-ui/react'<Kbd>F12</Kbd>Examples
Combinations
Render Kbd to showcase key combinations
import { HStack, Kbd } from "@chakra-ui/react"
export const KbdWithCombinations = () => {
return (
<HStack gap="1">
<Kbd>ctrl</Kbd>+<Kbd>shift</Kbd>+<Kbd>del</Kbd>
</HStack>
)
}
Function Keys
Here's an example of using Kbd to showcase function keys
import { HStack, Kbd } from "@chakra-ui/react"
export const KbdFunctionKeys = () => {
return (
<HStack>
<Kbd>⌘</Kbd>
<Kbd>⌥</Kbd>
<Kbd>⇧</Kbd>
<Kbd>⌃</Kbd>
</HStack>
)
}
Variants
Use the variant prop to change the appearance of the Kbd component
import { HStack, Kbd } from "@chakra-ui/react"
export const KbdWithVariants = () => {
return (
<HStack gap="4">
<Kbd variant="raised">Shift + Tab</Kbd>
<Kbd variant="outline">Shift + Tab</Kbd>
<Kbd variant="subtle">Shift + Tab</Kbd>
<Kbd variant="plain">Shift + Tab</Kbd>
</HStack>
)
}
Sizes
Use the size prop to change the size of the Kbd component
import { HStack, Kbd } from "@chakra-ui/react"
export const KbdWithSizes = () => {
return (
<HStack gap="4">
<Kbd size="sm">Shift + Tab</Kbd>
<Kbd size="md">Shift + Tab</Kbd>
<Kbd size="lg">Shift + Tab</Kbd>
</HStack>
)
}
Within Text
Use Kbd within text to highlight key combinations
Press F12 to open DevTools
import { Kbd, Text } from "@chakra-ui/react"
export const KbdWithinText = () => {
return (
<Text>
Press <Kbd>F12</Kbd> to open DevTools
</Text>
)
}
Kbd Group
KbdGroup displays a whole shortcut. Install it with
npx @saas-ui/cli add kbd-group.
import { KbdGroup } from '#components/ui/kbd-group'<KbdGroup>shift+X</KbdGroup>KbdGroup was called Command before v3. Command from
@chakra-ui/react is now the command palette. See
the migration guide.Shortcut string
Pass the shortcut as a string. Each key separated by + or a space renders as a
Kbd, while then and or render as plain text. Set the modifiers prop to
change which words stay as text.
'use client'
import { Stack } from '@chakra-ui/react'
import { KbdGroup } from '#components/ui/kbd-group'
export const KbdGroupBasic = () => {
return (
<Stack gap="3" align="flex-start">
<KbdGroup>⌘+K</KbdGroup>
<KbdGroup>shift+X</KbdGroup>
<KbdGroup>G then I</KbdGroup>
<KbdGroup>alt or option</KbdGroup>
</Stack>
)
}
Kbd children
Pass Kbd elements as children for full control over each key. size and
variant are passed to every key in the group.
'use client'
import { Kbd } from '@chakra-ui/react'
import { KbdGroup } from '#components/ui/kbd-group'
export const KbdGroupWithChildren = () => {
return (
<KbdGroup size="md" variant="subtle">
<Kbd>ctrl</Kbd>
<Kbd>shift</Kbd>
<Kbd>del</Kbd>
</KbdGroup>
)
}
Sizes
Use the size prop to change the size of the keys.
'use client'
import { Stack } from '@chakra-ui/react'
import { KbdGroup } from '#components/ui/kbd-group'
export const KbdGroupWithSizes = () => {
return (
<Stack gap="3" align="flex-start">
{(['xs', 'sm', 'md', 'lg'] as const).map((size) => (
<KbdGroup key={size} size={size}>
⌘+shift+P
</KbdGroup>
))}
</Stack>
)
}
In a tooltip
Inside a tooltip, the group is separated from the label with a dot.
'use client'
import { Button } from '#components/ui/button'
import { KbdGroup } from '#components/ui/kbd-group'
import { Tooltip } from '#components/ui/tooltip'
export const KbdGroupInTooltip = () => {
return (
<Tooltip
content={
<>
Go to inbox <KbdGroup>G then I</KbdGroup>
</>
}
>
<Button variant="outline" size="sm">
Inbox
</Button>
</Tooltip>
)
}
Props
| Prop | Default | Type |
|---|---|---|
colorPalette | 'gray' | 'gray' | 'zinc' | 'neutral' | 'stone' | 'red' | 'orange' | 'amber' | 'yellow' | 'lime' | 'green' | 'emerald' | 'teal' | 'cyan' | 'sky' | 'blue' | 'indigo' | 'violet' | 'purple' | 'fuchsia' | 'pink' | 'rose' | 'presence' | 'status' | 'sidebar' | 'sidebar.accent' | 'accent' | 'slate'The color palette of the component |
variant | 'subtle' | 'raised' | 'outline' | 'subtle' | 'plain'The variant of the component |
size | 'md' | 'sm' | 'md' | 'lg'The size of the component |
KbdGroup
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'xs' | 'sm' | 'md' | 'lg' | 'sm' | The size of the text and the keys |
variant | Kbd variant | - | The variant passed to each Kbd |
modifiers | string[] | ['then', 'or', '+'] | Words in a shortcut string that render as text, not as keys |