A one-sentence explanation on hover or keyboard focus. Button / IconButton take tooltip (and shortcut) directly; other elements wrap text with textTooltip(text, placement, shortcut) into a tooltip bubble set on tooltip; field definitions use HelpTip ⓘ. Long text wraps on its own, and the shortcut sits on the right.
Status: stable · Components: HelpTip, TooltipLabel
Import
Section titled “Import”import { HelpTip, TooltipLabel } from 'nacre'Without tooltip, an IconButton uses its label as the tooltip; a Button’s tooltip and shortcut are written separately, with the shortcut to the right of the text, one step lighter.
import { View } from 'nsh'import { Button, IconButton } from 'nacre'
export function TooltipUsage() { return ( <View class="flex-row flex-wrap items-center gap-2"> <IconButton icon="copy" label="Copy" /> <Button variant="outline" icon="export" tooltip="Export current filtered results" shortcut="⇧⌘E"> Export </Button> </View> )}Examples
Section titled “Examples”Multiple actions on one button
Section titled “Multiple actions on one button”Pass label and shortcut pairs to tooltip. Each action gets a row and the button keeps its accessible name.
import { ToolbarButton } from 'nacre'
export function TooltipShortcuts() { return ( <ToolbarButton testID="demo-tip-shortcuts" icon="sparkles" label="Writing assistant" tooltip={[ { label: 'Translate', shortcut: '⌥T' }, { label: 'Polish', shortcut: '⌥P' }, ]} /> )}Truncated user data
Section titled “Truncated user data”Give truncatable user data, like customer and company names, a full-text tooltip.
import { Text, View } from 'nsh'import { textTooltip, TEXT_SIZE } from 'nacre'
export function TooltipTruncated() { const company = 'Longbridge Securities (Hong Kong) Limited Institutional Client Services Greater China High-Net-Worth Client Dedicated Service Channel Secondary Sub-account' return ( <View class="w-[240px] max-w-full flex-row items-center gap-2"> <Text class={`shrink-0 ${TEXT_SIZE.small} text-muted-foreground`}>Customer</Text> <Text class={`flex-1 min-w-0 truncate ${TEXT_SIZE.small} text-foreground`} tooltip={textTooltip(company)}> {company} </Text> </View> )}Field help HelpTip
Section titled “Field help HelpTip”Definitions of metrics and fields: ⓘ opens on a 500ms hover, keyboard focus or press, and only one is open at a time.
import { Text, View } from 'nsh'import { HelpTip, TEXT_SIZE } from 'nacre'
export function TooltipHelpTip() { return ( <View class="flex-row items-center gap-1"> <Text class={`${TEXT_SIZE.small} text-muted-foreground`}>First response time</Text> <HelpTip text="From the customer’s first message to the agent’s first reply, excluding queue time" /> </View> )}Placement and shortcut
Section titled “Placement and shortcut”TooltipLabel anchors the hint and keyboard focus ring to a padded frame. Standard labels use 8pt horizontal and 4pt vertical padding. Compact metadata uses 6pt and 2pt.
import { View, cleanup, keymap } from 'nsh'import type { ViewRef } from 'nsh'import { TooltipLabel } from 'nacre'
export function TooltipPlacement() { const synced = 'Last synced: today 14:05' const labels = [ { label: 'Synced', tooltip: synced }, { label: 'Synced (tooltip above)', tooltip: synced, placement: 'top' as const }, { label: 'Next chat', tooltip: 'Go to next chat', shortcut: '⌘]' }, ] const targets: ViewRef[] = [] let unbind: (() => void) | undefined const release = () => { unbind?.(); unbind = undefined } cleanup(release) return ( <View class="flex-row flex-wrap items-center gap-4"> {labels.map((item, index) => ( <View onFocusOut={release} onFocusIn={() => { release() unbind = keymap.bind({ left: () => targets[index - 1]?.focus(), right: () => targets[index + 1]?.focus() }) }}> <TooltipLabel testID={`demo-tooltip-label-${index + 1}`} viewRef={(node) => (targets[index] = node)} label={item.label} tooltip={item.tooltip} placement={item.placement} shortcut={item.shortcut} /> </View> ))} </View> )}Keyboard
Section titled “Keyboard”| Key | Action |
|---|---|
| Tab | The tooltip appears when a control with a tooltip is focused |
| ← → | In the placement example, visit the three labels in the same order as Tab. |
| Esc | Dismiss the HelpTip tooltip |
Accessibility
Section titled “Accessibility”- TooltipLabel uses the visible text as its name and adds the extra detail and shortcut in its accessible description.
- HelpTip’s accessible name is the tooltip text, and its role is button.
- IconButton’s accessible name is label, which the tooltip also uses by default; an element whose meaning comes only from its tooltip needs its own accessibilityLabel.
Do / Don’t
Section titled “Do / Don’t”Do
- Give truncated user data a full-text tooltip
- Use the shortcut argument for shortcuts instead of putting them in the text
- Keep tooltips to one sentence
Don’t
- Put actions or links in it (they can’t be clicked in a tooltip; put them in the page or a Dialog)
- Repeat text already on the button
- Pass a string straight to tooltip
Property descriptions follow the Chinese source comments.
HelpTip
Section titled “HelpTip”| Prop | Type | Default | Description |
|---|---|---|---|
text * |
string |
— | |
testID |
string |
— |
* required
TooltipLabel
Section titled “TooltipLabel”| Prop | Type | Default | Description |
|---|---|---|---|
label * |
string |
— | |
tooltip * |
string |
— | |
placement |
'top' | 'bottom' |
— | |
size |
'sm' | 'md' |
— | sm 适配 20pt 的紧凑元信息行。 |
shortcut |
string |
— | |
viewRef |
(node: ViewRef) => void |
— | 把键盘焦点交给这段文字时,聚焦提示本身。 |
testID |
string |
— |
* required