@antadesign/anta 0.3.33 → 0.3.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +14 -1
- package/README.md +9 -0
- package/dist/anta_helpers.d.ts +46 -30
- package/dist/anta_helpers.js +66 -25
- package/dist/bundle.css +1 -1
- package/dist/bundle.js +2 -1353
- package/dist/components/Banner.d.ts +25 -40
- package/dist/components/Banner.js +15 -17
- package/dist/components/Breadcrumbs.d.ts +0 -1
- package/dist/components/Breadcrumbs.js +0 -1
- package/dist/components/Button.d.ts +2 -3
- package/dist/components/Button.js +1 -0
- package/dist/components/ButtonCopy.js +3 -2
- package/dist/components/Calendar.js +13 -13
- package/dist/components/Card.d.ts +9 -17
- package/dist/components/Card.js +50 -46
- package/dist/components/Dialog.d.ts +1 -0
- package/dist/components/Dialog.js +16 -10
- package/dist/components/Expander.d.ts +6 -21
- package/dist/components/Expander.js +24 -23
- package/dist/components/Icon.d.ts +8 -14
- package/dist/components/Input.d.ts +77 -96
- package/dist/components/Input.js +23 -27
- package/dist/components/InputAutocomplete.d.ts +29 -10
- package/dist/components/InputAutocomplete.js +25 -8
- package/dist/components/InputDate.d.ts +0 -1
- package/dist/components/InputDate.js +2 -3
- package/dist/components/InputTime.d.ts +10 -4
- package/dist/components/InputTime.js +20 -16
- package/dist/components/Loader.d.ts +2 -2
- package/dist/components/Menu.d.ts +5 -4
- package/dist/components/Menu.js +13 -8
- package/dist/components/MenuItem.js +1 -14
- package/dist/components/MenuItemCopy.js +2 -2
- package/dist/components/Panel.d.ts +3 -1
- package/dist/components/Panel.js +17 -11
- package/dist/components/Progress.d.ts +21 -23
- package/dist/components/Progress.js +13 -9
- package/dist/components/RadioGroup.js +6 -8
- package/dist/components/{select-parts.css → Select.css} +1 -1
- package/dist/components/Select.d.ts +53 -36
- package/dist/components/Select.js +53 -98
- package/dist/components/SelectFaceted.d.ts +7 -4
- package/dist/components/SelectFaceted.js +21 -10
- package/dist/components/Slider.d.ts +28 -11
- package/dist/components/Slider.js +20 -20
- package/dist/components/Steps.css +1 -1
- package/dist/components/Steps.d.ts +0 -1
- package/dist/components/Steps.js +1 -12
- package/dist/components/Tabs.d.ts +17 -20
- package/dist/components/Tabs.js +7 -9
- package/dist/components/Text.d.ts +55 -36
- package/dist/components/Text.js +35 -22
- package/dist/components/Title.d.ts +19 -27
- package/dist/components/Title.js +2 -1
- package/dist/components/Toaster.js +9 -2
- package/dist/components/Tooltip.d.ts +10 -15
- package/dist/components/copy-props.d.ts +14 -3
- package/dist/components/copy-props.js +14 -3
- package/dist/components/select-tree.d.ts +24 -0
- package/dist/components/select-tree.js +35 -0
- package/dist/element-base.d.ts +10 -0
- package/dist/element-base.js +15 -0
- package/dist/elements/a-avatar.css +1 -1
- package/dist/elements/a-avatar.js +2 -28
- package/dist/elements/a-banner.css +1 -1
- package/dist/elements/a-banner.d.ts +4 -1
- package/dist/elements/a-banner.js +22 -112
- package/dist/elements/a-breadcrumbs.d.ts +1 -0
- package/dist/elements/a-breadcrumbs.js +1 -0
- package/dist/elements/a-button.css +1 -1
- package/dist/elements/a-button.d.ts +10 -7
- package/dist/elements/a-button.js +18 -1
- package/dist/elements/a-calendar.d.ts +14 -13
- package/dist/elements/a-calendar.js +29 -24
- package/dist/elements/a-card.css +1 -1
- package/dist/elements/a-card.d.ts +0 -9
- package/dist/elements/a-card.js +0 -184
- package/dist/elements/a-checkbox.css +1 -1
- package/dist/elements/a-copy.css +1 -1
- package/dist/elements/a-copy.d.ts +1 -5
- package/dist/elements/a-copy.js +129 -108
- package/dist/elements/a-dialog.css +1 -1
- package/dist/elements/a-dialog.d.ts +1 -1
- package/dist/elements/a-dialog.js +68 -194
- package/dist/elements/a-expander.css +1 -1
- package/dist/elements/a-expander.d.ts +4 -30
- package/dist/elements/a-expander.js +85 -344
- package/dist/elements/a-icon.d.ts +5 -23
- package/dist/elements/a-icon.js +1 -2
- package/dist/elements/a-input-date.d.ts +1 -0
- package/dist/elements/a-input-date.js +1 -0
- package/dist/elements/a-input-time.css +1 -1
- package/dist/elements/a-input-time.d.ts +2 -1
- package/dist/elements/a-input-time.js +101 -168
- package/dist/elements/a-input.css +1 -1
- package/dist/elements/a-input.d.ts +10 -8
- package/dist/elements/a-input.js +155 -230
- package/dist/elements/a-loader.d.ts +5 -8
- package/dist/elements/a-loader.js +1 -2
- package/dist/elements/a-menu-item.css +1 -1
- package/dist/elements/a-menu-item.d.ts +5 -3
- package/dist/elements/a-menu-item.js +5 -1
- package/dist/elements/a-menu.css +1 -1
- package/dist/elements/a-menu.d.ts +5 -7
- package/dist/elements/a-menu.js +383 -299
- package/dist/elements/a-panel.css +1 -1
- package/dist/elements/a-panel.js +19 -37
- package/dist/elements/a-progress.css +1 -1
- package/dist/elements/a-progress.d.ts +0 -22
- package/dist/elements/a-progress.js +0 -100
- package/dist/elements/a-radio-group.d.ts +1 -1
- package/dist/elements/a-radio-group.js +6 -4
- package/dist/elements/a-select-faceted.d.ts +1 -0
- package/dist/elements/a-select-faceted.js +1 -0
- package/dist/elements/a-select.d.ts +1 -0
- package/dist/elements/a-select.js +1 -0
- package/dist/elements/a-slider.css +1 -1
- package/dist/elements/a-slider.d.ts +11 -3
- package/dist/elements/a-slider.js +244 -242
- package/dist/elements/a-steps.d.ts +1 -0
- package/dist/elements/a-steps.js +1 -0
- package/dist/elements/a-switch.css +1 -1
- package/dist/elements/a-tab.css +1 -1
- package/dist/elements/a-tabpanel.d.ts +2 -2
- package/dist/elements/a-tabpanel.js +13 -3
- package/dist/elements/a-tabs.css +1 -1
- package/dist/elements/a-tabs.d.ts +1 -1
- package/dist/elements/a-tabs.js +6 -4
- package/dist/elements/a-tag.css +1 -1
- package/dist/elements/a-tag.d.ts +1 -0
- package/dist/elements/a-tag.js +1 -0
- package/dist/elements/a-text.css +1 -1
- package/dist/elements/a-text.d.ts +6 -43
- package/dist/elements/a-text.js +110 -193
- package/dist/elements/a-title.css +1 -1
- package/dist/elements/a-title.d.ts +1 -0
- package/dist/elements/a-title.js +1 -0
- package/dist/elements/a-toast.css +1 -1
- package/dist/elements/a-toast.d.ts +10 -45
- package/dist/elements/a-toast.js +80 -66
- package/dist/elements/a-toaster.css +1 -1
- package/dist/elements/a-toaster.js +9 -44
- package/dist/elements/a-tooltip.css +1 -1
- package/dist/elements/a-tooltip.d.ts +1 -1
- package/dist/elements/a-tooltip.js +142 -136
- package/dist/elements/copy-behavior.d.ts +1 -1
- package/dist/elements/copy-behavior.js +21 -21
- package/dist/elements/index.d.ts +9 -3
- package/dist/elements/index.js +6 -6
- package/dist/elements/input-focus-modality.d.ts +15 -0
- package/dist/elements/input-focus-modality.js +44 -0
- package/dist/elements/input-trailing-actions.d.ts +5 -0
- package/dist/elements/input-trailing-actions.js +38 -0
- package/dist/elements/shadow-aria.d.ts +2 -0
- package/dist/elements/shadow-aria.js +2 -1
- package/dist/elements/value-input.d.ts +3 -0
- package/dist/elements/value-input.js +12 -0
- package/dist/general_types.d.ts +103 -96
- package/dist/index.d.ts +1 -1
- package/dist/input-events.d.ts +4 -0
- package/dist/input-events.js +15 -0
- package/dist/jsx-runtime.d.ts +70 -23
- package/dist/jsx-runtime.js +26 -19
- package/dist/native-event-props.d.ts +2 -0
- package/dist/native-event-props.js +10 -0
- package/dist/reset.css +1 -1
- package/dist/theme-antithesis.css +10 -1
- package/dist/theme-antune.css +1 -1
- package/docs/accessibility.md +17 -3
- package/docs/changelog.md +384 -2
- package/docs/comparison.md +2 -2
- package/docs/components/avatar.md +5 -0
- package/docs/components/banner.md +117 -187
- package/docs/components/breadcrumbs.md +9 -6
- package/docs/components/button.md +22 -0
- package/docs/components/card.md +74 -28
- package/docs/components/checkbox.md +9 -10
- package/docs/components/dialog.md +83 -32
- package/docs/components/expander.md +198 -435
- package/docs/components/icon.md +11 -17
- package/docs/components/input-autocomplete.md +152 -52
- package/docs/components/input-date.md +175 -148
- package/docs/components/input-time.md +81 -38
- package/docs/components/input.md +343 -349
- package/docs/components/loader.md +2 -1
- package/docs/components/menu.md +35 -6
- package/docs/components/panel.md +18 -0
- package/docs/components/progress.md +83 -49
- package/docs/components/radio.md +39 -43
- package/docs/components/select-faceted.md +54 -7
- package/docs/components/select.md +390 -386
- package/docs/components/slider.md +136 -19
- package/docs/components/steps.md +6 -3
- package/docs/components/switch.md +8 -9
- package/docs/components/tabs.md +110 -104
- package/docs/components/text.md +110 -86
- package/docs/components/title.md +47 -33
- package/docs/components/toaster.md +242 -84
- package/docs/components/tooltip.md +204 -113
- package/docs/install-config.md +461 -96
- package/docs/packages/plot.md +228 -143
- package/docs/theming.md +29 -13
- package/package.json +43 -4
- package/theme-antithesis-license.md +66 -0
|
@@ -1,169 +1,260 @@
|
|
|
1
1
|
# Tooltip
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
It shows on hover (after a short `delay`) and on keyboard focus, and dismisses
|
|
8
|
-
on mouse leave, blur, Esc, or when the anchor scrolls away. On touch
|
|
9
|
-
devices — where there's no hover and a tap shouldn't surface it — it opens on
|
|
10
|
-
**press-and-hold** and lingers briefly after you lift, so it stays readable. By
|
|
11
|
-
default the bubble is **pinned** under the anchor; pass `follow` to make it
|
|
12
|
-
**track the cursor** (fading out as the cursor moves away), or `interactive` to
|
|
13
|
-
make it hoverable and clickable (for content like links).
|
|
14
|
-
|
|
15
|
-
When the anchor implements **`getAnchorRect(): DOMRect`**, the bubble positions
|
|
16
|
-
against that rect instead of the anchor's full box. Anta's `Input` reports its
|
|
17
|
-
field box, so a tooltip on an `<Input>` points at the field, not the surrounding
|
|
18
|
-
label or hint.
|
|
3
|
+
Use Tooltip for supplementary explanations and the full text of clipped labels.
|
|
4
|
+
Place it inside the element it describes. It takes no space in that element's
|
|
5
|
+
layout. Keep essential instructions and actions available without a tooltip.
|
|
19
6
|
|
|
20
7
|
## Examples
|
|
21
8
|
|
|
9
|
+
Hover Status for a text explanation, focus the underlined button with Tab,
|
|
10
|
+
follow the cursor, or enter the interactive bubble to use its link.
|
|
11
|
+
|
|
22
12
|
```tsx
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<Button
|
|
33
|
-
|
|
34
|
-
</Button>
|
|
13
|
+
<div style={{ display: 'flex', gap: '16px', alignItems: 'center', flexWrap: 'wrap' }}>
|
|
14
|
+
<span style={{ cursor: 'help', display: 'inline-flex', alignItems: 'center', gap: '4px' }}>
|
|
15
|
+
<span>Status</span>
|
|
16
|
+
<Icon shape="info" size={16} style={{ color: 'var(--text-5)' }} />
|
|
17
|
+
<Tooltip placement="top">Last checked 2 minutes ago</Tooltip>
|
|
18
|
+
</span>
|
|
19
|
+
<Button priority="tertiary" underline="dashed" label="Focus me with the keyboard">
|
|
20
|
+
<Tooltip delay={50}>Shows on focus, dismiss with Esc</Tooltip>
|
|
21
|
+
</Button>
|
|
22
|
+
<Button label="Follow the cursor">
|
|
23
|
+
<Tooltip follow>Tracks the pointer, fades as you leave</Tooltip>
|
|
24
|
+
</Button>
|
|
25
|
+
<Button label="Interact">
|
|
26
|
+
<Tooltip interactive placement="top">
|
|
27
|
+
See the <a href="/install/">full guide</a> for details
|
|
28
|
+
</Tooltip>
|
|
29
|
+
</Button>
|
|
30
|
+
</div>
|
|
31
|
+
```
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
<Button label="Follow the cursor">
|
|
38
|
-
<Tooltip follow>Tracks the pointer, fades as you leave</Tooltip>
|
|
39
|
-
</Button>
|
|
33
|
+
## Hover and keyboard focus
|
|
40
34
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
Hover the button or reach it with Tab to show its explanation after a delay.
|
|
36
|
+
Escape dismisses it. Leaving the anchor, moving focus away, or scrolling also
|
|
37
|
+
closes it. On touch screens, hold the anchor for 500ms; a quick tap does not open
|
|
38
|
+
it. After release, a touch tooltip remains for 1.5 seconds.
|
|
39
|
+
|
|
40
|
+
Give the trigger an accessible name independently. Put explanations that should
|
|
41
|
+
be available before opening on the trigger with authored ARIA. Here,
|
|
42
|
+
`aria-description` supplies the short description in both open and closed states.
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
<Button label="Publish" aria-description="Makes the draft public">
|
|
46
|
+
<Tooltip id="publish-tooltip" delay={50}>Makes the draft public</Tooltip>
|
|
46
47
|
</Button>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Placement
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
<Button label="
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
Choose `top` or `left` to prefer another side. Tooltip flips when that side has
|
|
53
|
+
insufficient room and keeps the bubble within the viewport.
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
<Button label="Below"><Tooltip>Below the anchor</Tooltip></Button>
|
|
57
|
+
<Button label="Above"><Tooltip placement="top">Above the anchor</Tooltip></Button>
|
|
58
|
+
<Button label="Beside"><Tooltip placement="left">Beside the anchor</Tooltip></Button>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Follow the cursor
|
|
62
|
+
|
|
63
|
+
Use `follow` for explanations attached to a larger pointer target. The bubble
|
|
64
|
+
tracks the cursor and fades with distance as the pointer leaves. Moving between
|
|
65
|
+
two `follow` anchors skips the next delay while the previous tooltip is open or
|
|
66
|
+
within its 300ms grace period. Pinned tooltips keep their configured delay.
|
|
67
|
+
Keyboard and touch openings stay anchored to the target.
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
<Button label="First"><Tooltip follow>First explanation</Tooltip></Button>
|
|
71
|
+
<Button label="Second"><Tooltip follow>Second explanation</Tooltip></Button>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Interactive content
|
|
75
|
+
|
|
76
|
+
Pass `interactive` to enter the bubble with the pointer or keyboard and use its
|
|
77
|
+
content. It stays pinned even when `follow` is present. Move from the trigger to
|
|
78
|
+
the link, or focus the trigger and press Tab. Escape dismisses the bubble.
|
|
79
|
+
|
|
80
|
+
This option preserves Tooltip's existing tooltip semantics. The ARIA tooltip
|
|
81
|
+
pattern describes nonfocusable content; use Menu or Dialog for essential actions
|
|
82
|
+
that need an explicit trigger and popup semantics.
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
<Button label="Help" aria-description="Read the installation guide for setup details">
|
|
86
|
+
<Tooltip id="help-tooltip" interactive placement="top">
|
|
87
|
+
Read the <a href="/install/">installation guide</a>.
|
|
55
88
|
</Tooltip>
|
|
56
89
|
</Button>
|
|
57
90
|
```
|
|
58
91
|
|
|
59
|
-
|
|
92
|
+
## Show only when truncated
|
|
60
93
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
94
|
+
Use `truncatedOnly` when the explanation repeats a label. A label that fits does
|
|
95
|
+
not open a bubble. Hover both labels to compare a clipped target with one that
|
|
96
|
+
fits.
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
<div style={{ display: 'flex', gap: '28px', alignItems: 'flex-start', flexWrap: 'wrap' }}>
|
|
100
|
+
<span style={{ display: 'inline-block', maxWidth: '130px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', cursor: 'help' }}>
|
|
101
|
+
A long label that gets truncated
|
|
102
|
+
<Tooltip truncatedOnly>A long label that gets truncated</Tooltip>
|
|
103
|
+
</span>
|
|
104
|
+
<span style={{ display: 'inline-block', cursor: 'help' }}>
|
|
105
|
+
Short label
|
|
106
|
+
<Tooltip truncatedOnly>Short label</Tooltip>
|
|
107
|
+
</span>
|
|
108
|
+
</div>
|
|
66
109
|
```
|
|
67
110
|
|
|
68
|
-
|
|
111
|
+
Text with `truncate` already creates an automatic tooltip for clipped,
|
|
112
|
+
non-expandable content.
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
<Text truncate style={{ maxWidth: '160px' }}>
|
|
116
|
+
A long release title that does not fit in this space
|
|
117
|
+
</Text>
|
|
118
|
+
<Text truncate>Short title</Text>
|
|
119
|
+
```
|
|
69
120
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
next fades in (no blink). If either tooltip does not have `follow`, the next
|
|
73
|
-
tooltip waits for its configured delay. With `follow` tooltips (used below to
|
|
74
|
-
show it), the outgoing bubble also keeps
|
|
75
|
-
trailing the cursor and fades by distance from its anchor (transparent by ~100px
|
|
76
|
-
away), so a near hop reads as a smooth cross-fade and a far one is already gone.
|
|
77
|
-
With **nested** anchors, the inner (descendant) tooltip wins while you're over
|
|
78
|
-
it, and the outer takes back over when you leave. Hover the examples to feel it.
|
|
121
|
+
Nest your own Tooltip inside Text to replace its automatic explanation. An empty
|
|
122
|
+
explicit Tooltip suppresses the automatic one.
|
|
79
123
|
|
|
80
124
|
```tsx
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
<
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// Nested — wrap stray text in a <span> so the tooltip stays a direct child of
|
|
87
|
-
// the box (its anchor). The inner tooltip wins while you're over the inner button.
|
|
88
|
-
<div tabIndex={0}>
|
|
89
|
-
<span>Outer box</span>
|
|
90
|
-
<Tooltip follow>Outer tooltip</Tooltip>
|
|
91
|
-
<Button label="Inner button"><Tooltip follow>Inner tooltip</Tooltip></Button>
|
|
92
|
-
</div>
|
|
125
|
+
<Text truncate style={{ maxWidth: '160px' }}>
|
|
126
|
+
A long release title with a custom explanation
|
|
127
|
+
<Tooltip>This release includes keyboard navigation improvements.</Tooltip>
|
|
128
|
+
</Text>
|
|
93
129
|
```
|
|
94
130
|
|
|
95
|
-
|
|
131
|
+
## Adjacent and nested tooltips
|
|
96
132
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
default it measures the nearest Anta ellipsizing label (`a-tab-label` /
|
|
101
|
-
`a-button-label`) inside the anchor, then the anchor itself; point it elsewhere with
|
|
102
|
-
**`truncatedSelector`**. Hover both — only the clipped one reveals its full text:
|
|
133
|
+
One tooltip is open per document. A tooltip on a nested anchor takes precedence
|
|
134
|
+
while that anchor is active. Returning to the outer anchor makes its explanation
|
|
135
|
+
available again.
|
|
103
136
|
|
|
104
137
|
```tsx
|
|
105
|
-
{
|
|
106
|
-
|
|
107
|
-
<
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
138
|
+
<div style={{ display: 'flex', gap: '40px', alignItems: 'flex-start', flexWrap: 'wrap' }}>
|
|
139
|
+
<div style={{ display: 'flex', gap: '12px' }}>
|
|
140
|
+
<Button label="First"><Tooltip follow>First tooltip</Tooltip></Button>
|
|
141
|
+
<Button label="Second"><Tooltip follow>Second tooltip</Tooltip></Button>
|
|
142
|
+
</div>
|
|
143
|
+
<div tabIndex={0} aria-label="Outer box" style={{ padding: '20px', border: '1px dashed var(--border-4)', borderRadius: '6px', cursor: 'help' }}>
|
|
144
|
+
<span>Outer box</span>
|
|
145
|
+
<Tooltip follow>Outer tooltip</Tooltip>
|
|
146
|
+
<div style={{ marginTop: '12px' }}>
|
|
147
|
+
<Button label="Inner button"><Tooltip follow>Inner tooltip</Tooltip></Button>
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
111
151
|
```
|
|
112
152
|
|
|
113
|
-
|
|
153
|
+
## Content and shape
|
|
114
154
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
is
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
155
|
+
Content can include text, icons, and markup. An empty or whitespace-only tooltip
|
|
156
|
+
does not open. Clearing an open tooltip's content closes it; subsequent content
|
|
157
|
+
is available on the next interaction. Use `round` for a softer shape.
|
|
158
|
+
|
|
159
|
+
```tsx
|
|
160
|
+
<Button label="Release status">
|
|
161
|
+
<Tooltip round><strong>Healthy</strong> · Checked two minutes ago</Tooltip>
|
|
162
|
+
</Button>
|
|
163
|
+
<Button icon="info" aria-label="Action details">
|
|
164
|
+
<Tooltip placement="top"><strong>Heads up</strong> · This action cannot be undone</Tooltip>
|
|
165
|
+
</Button>
|
|
166
|
+
<Button label="No explanation"><Tooltip>{''}</Tooltip></Button>
|
|
167
|
+
```
|
|
121
168
|
|
|
122
169
|
## Component props
|
|
123
170
|
|
|
124
171
|
| Prop | Type | Default | Description |
|
|
125
172
|
|------|------|---------|-------------|
|
|
126
|
-
| `children?` | ReactNode | — |
|
|
127
|
-
| `delay?` | number | 300 |
|
|
173
|
+
| `children?` | ReactNode | — | Supplementary text or markup. Content stays in light DOM for application CSS. |
|
|
174
|
+
| `delay?` | number | 300 | Wait in milliseconds after hover or keyboard focus. Use `50` for a short delay. |
|
|
128
175
|
| `follow?` | boolean | — | Follow the cursor instead of pinning under the anchor. The bubble is pinned (anchored beneath the target) by default; pass `follow` for the cursor-tracking behavior, which fades by distance as the cursor leaves. |
|
|
129
|
-
| `interactive?` | boolean | — |
|
|
176
|
+
| `interactive?` | boolean | — | Keep content available while the pointer or keyboard focus is inside it. Enables pointer events and pins the bubble even with `follow`. Essential actions belong in a Menu or Dialog with an explicit trigger. |
|
|
130
177
|
| `placement?` | 'top' \| 'bottom' \| 'left' | bottom | Which side of the anchor the bubble prefers. Auto-flips to the other side when there isn't room. |
|
|
131
178
|
| `round?` | boolean \| number \| string | — | Round the bubble to a 20px radius (matching a round menu). Pass a `number` (px) or a CSS length string for a custom radius. |
|
|
132
179
|
| `truncatedOnly?` | boolean | — | Only show when the target is actually truncated (its text overflows and is ellipsized); a label that fits gets no tooltip. The check is a UI-thread layout read, re-measured on each show. By default it measures every Anta ellipsizing label part inside the anchor, then the anchor itself — override with `truncatedSelector`. |
|
|
133
180
|
| `truncatedSelector?` | string | — | CSS selector (resolved within the anchor) for the element or elements whose overflow decides whether a `truncatedOnly` tooltip shows. |
|
|
134
181
|
|
|
135
|
-
|
|
182
|
+
`truncatedOnly` measures the anchor's reported truncation or its `a-tab-label`,
|
|
183
|
+
`a-button-label`, and `a-step-hint` regions. `truncatedSelector` selects a different
|
|
184
|
+
measurement target. Measurements are refreshed when opening.
|
|
185
|
+
|
|
186
|
+
A custom numeric or length `round` prop emits an inline CSS variable. If your CSP
|
|
187
|
+
blocks style attributes, use external `::part(bubble)` CSS for a custom radius.
|
|
136
188
|
|
|
137
|
-
|
|
189
|
+
## Web Component
|
|
138
190
|
|
|
139
|
-
Place
|
|
191
|
+
Place `a-tooltip` directly inside its anchor. The author owns markup, styles,
|
|
192
|
+
accessible names, and descriptions. Tooltip does not add attributes
|
|
193
|
+
to its anchor or rewrite the supplied content.
|
|
140
194
|
|
|
141
195
|
```html
|
|
142
|
-
<a-button role="button" tabindex="0"
|
|
196
|
+
<a-button role="button" tabindex="0" aria-label="Publish" aria-description="Makes the draft public">
|
|
143
197
|
<a-button-label>Publish</a-button-label>
|
|
144
|
-
<a-tooltip>
|
|
198
|
+
<a-tooltip id="raw-publish-tooltip">Makes the draft public</a-tooltip>
|
|
145
199
|
</a-button>
|
|
146
200
|
```
|
|
147
201
|
|
|
202
|
+
Referencing the Tooltip host with `aria-describedby` does not provide a reliable
|
|
203
|
+
description while its internal popover is hidden. Use an authored
|
|
204
|
+
`aria-description`, or reference separate application-owned descriptive content
|
|
205
|
+
that remains available to assistive technology.
|
|
206
|
+
|
|
207
|
+
Raw attributes include `delay`, `placement`, `round`, `follow`, `interactive`,
|
|
208
|
+
`truncated-only`, and `truncated-selector`. Boolean attributes use presence.
|
|
209
|
+
An anchor can implement `getAnchorRect(): DOMRect` to advertise a smaller
|
|
210
|
+
positioning region; Input reports its field instead of its label and hint.
|
|
211
|
+
|
|
212
|
+
Default styles load from the external component stylesheet. Under CSP, allow
|
|
213
|
+
that same-origin stylesheet and the browser entry. Runtime positioning updates
|
|
214
|
+
only Tooltip's owned shadow elements. Input and Menu also load their defaults
|
|
215
|
+
from external CSS. Custom values serialized into HTML style attributes remain
|
|
216
|
+
subject to the [CSP guidance](../install-config.md#content-security-policy).
|
|
217
|
+
|
|
218
|
+
Reduced motion disables both fades. Older supported browsers can omit parts of
|
|
219
|
+
the native popover transition while retaining the content and interaction.
|
|
220
|
+
|
|
148
221
|
## Styling
|
|
149
222
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
the demo:
|
|
223
|
+
Style the visible surface with `::part(bubble)`. Supplied content remains in light
|
|
224
|
+
DOM, so application selectors can style its text. `::part(container)` reaches
|
|
225
|
+
the outer popover and its opening/closing transition. Keep its positioning and
|
|
226
|
+
pointer behavior intact when changing appearance.
|
|
227
|
+
|
|
228
|
+
The classes below identify this demonstration; use your own selectors.
|
|
157
229
|
|
|
158
230
|
```css
|
|
159
|
-
|
|
160
|
-
a-tooltip.fancy::part(bubble) {
|
|
231
|
+
a-tooltip.custom-tooltip::part(bubble) {
|
|
161
232
|
background: #1a161d;
|
|
162
233
|
border-radius: 10px;
|
|
163
234
|
padding: 8px 12px;
|
|
164
|
-
box-shadow: 0 4px 18px
|
|
165
|
-
backdrop-filter: none;
|
|
235
|
+
box-shadow: 0 4px 18px color-mix(in oklch, black 35%, transparent);
|
|
236
|
+
backdrop-filter: none;
|
|
237
|
+
}
|
|
238
|
+
.custom-tooltip-text {
|
|
239
|
+
color: #fff;
|
|
240
|
+
font-size: 15px;
|
|
241
|
+
font-weight: 600;
|
|
242
|
+
letter-spacing: 0.01em;
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Example
|
|
247
|
+
|
|
248
|
+
```tsx
|
|
249
|
+
import { Tooltip, Button } from '@antadesign/anta'
|
|
250
|
+
|
|
251
|
+
function Demo() {
|
|
252
|
+
return (
|
|
253
|
+
<div className="container">
|
|
254
|
+
<Button label="Hover me">
|
|
255
|
+
<Tooltip delay={300}>Edit my props or code</Tooltip>
|
|
256
|
+
</Button>
|
|
257
|
+
</div>
|
|
258
|
+
)
|
|
166
259
|
}
|
|
167
|
-
/* the slotted content — a class on what you pass to <Tooltip> */
|
|
168
|
-
.tip-rich { color: #fff; font-size: 15px; font-weight: 600; letter-spacing: 0.01em; }
|
|
169
260
|
```
|