Tooltip · 补充提示
触发控件应已有清楚的文字或可访问名称。可以在提示里补充快捷键或操作说明。必读的信息请直接写在页面上;需要放置链接、输入框等交互内容时使用 Popover。
Live example
Open playground ↗App.tsx
'use client'
import { Button, Tooltip } from '@ancrel/ui'
import '@ancrel/tokens/css'
import '@ancrel/ui/styles.css'
export default function App() {
return <Tooltip content="Keyboard shortcut: Ctrl + P" placement="bottom">
<Button>Print</Button>
</Tooltip>
}
Expected behavior
Expected behavior
Focus Print to read its keyboard shortcut immediately, or hover briefly. The button keeps its name. Escape removes the hint without moving focus.
鼠标与键盘
悬停默认等待 350 毫秒,delayMs 可调整等待时间。提前移开会取消显示。键盘聚焦时立即显示,并通过 aria-describedby 在已有描述后追加提示。鼠标可以移到提示内容上阅读。
按 Escape 隐藏提示,焦点仍在原控件。Tab 继续页面原有的导航。提示同时由悬停和焦点保持时,两者都离开后才会自动隐藏。
Props
| Prop | Type | Required | Default |
|---|---|---|---|
children | ReactElement | Yes | — |
content | ReactNode | Yes | — |
delayMs | number | No | — |
key | React.Key | null | undefined | No | — |
placement | 'top' | 'bottom' | 'left' | 'right' | No | — |
ref | React.Ref<HTMLDivElement> | undefined | No | — |
State matrix
| State | Theme / density |
|---|---|
| default | dark/compact, dark/comfortable, light/compact, light/comfortable |
Constraints
- Give the trigger a visible or accessible name independent of the hint.
- Keep tooltip content noninteractive and show essential instructions in the page.
Anti-patterns
- Using a hover-only hint as the sole name of an icon button.
- Placing a link or other focusable control inside a tooltip.