@ui-sdk/vue 0.0.0-stage → 0.1.0-beta.1
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 +202 -0
- package/README.md +10 -2
- package/dist/accordion.d.ts +561 -0
- package/dist/accordion.js +24 -0
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +7 -0
- package/dist/alert-dialog.d.ts +231 -0
- package/dist/alert-dialog.js +33 -0
- package/dist/async-options.d.ts +18 -0
- package/dist/async-options.js +40 -0
- package/dist/autocomplete.d.ts +384 -0
- package/dist/autocomplete.js +344 -0
- package/dist/avatar.d.ts +40 -0
- package/dist/avatar.js +28 -0
- package/dist/button.d.ts +52 -0
- package/dist/button.js +43 -0
- package/dist/calendar-context.d.ts +10 -0
- package/dist/calendar-context.js +7 -0
- package/dist/calendar.d.ts +311 -0
- package/dist/calendar.js +349 -0
- package/dist/carousel.d.ts +236 -0
- package/dist/carousel.js +204 -0
- package/dist/checkbox.d.ts +211 -0
- package/dist/checkbox.js +151 -0
- package/dist/children.d.ts +41 -0
- package/dist/children.js +135 -0
- package/dist/collapsible.d.ts +54 -0
- package/dist/collapsible.js +18 -0
- package/dist/color-picker.d.ts +187 -0
- package/dist/color-picker.js +158 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.js +21 -0
- package/dist/combobox.d.ts +517 -0
- package/dist/combobox.js +531 -0
- package/dist/command.d.ts +322 -0
- package/dist/command.js +345 -0
- package/dist/controller-target.d.ts +49 -0
- package/dist/controller-target.js +112 -0
- package/dist/create-parts.d.ts +126 -0
- package/dist/create-parts.js +206 -0
- package/dist/date-input.d.ts +133 -0
- package/dist/date-input.js +31 -0
- package/dist/date-picker.d.ts +328 -0
- package/dist/date-picker.js +354 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +59 -0
- package/dist/dialog-parts.d.ts +259 -0
- package/dist/dialog-parts.js +300 -0
- package/dist/dialog.d.ts +251 -0
- package/dist/dialog.js +25 -0
- package/dist/drawer.d.ts +304 -0
- package/dist/drawer.js +373 -0
- package/dist/editor-context.d.ts +4 -0
- package/dist/editor-context.js +5 -0
- package/dist/field-context.d.ts +26 -0
- package/dist/field-context.js +44 -0
- package/dist/field.d.ts +154 -0
- package/dist/field.js +240 -0
- package/dist/file-input.d.ts +212 -0
- package/dist/file-input.js +255 -0
- package/dist/form-inputs.d.ts +16 -0
- package/dist/form-inputs.js +25 -0
- package/dist/gesture.d.ts +1 -0
- package/dist/gesture.js +15 -0
- package/dist/history.d.ts +2 -0
- package/dist/history.js +11 -0
- package/dist/hover-card.d.ts +137 -0
- package/dist/hover-card.js +153 -0
- package/dist/image-cropper.d.ts +74 -0
- package/dist/image-cropper.js +36 -0
- package/dist/image.d.ts +2 -0
- package/dist/image.js +5 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +60 -0
- package/dist/input.d.ts +120 -0
- package/dist/input.js +73 -0
- package/dist/item-icon.d.ts +34 -0
- package/dist/item-icon.js +63 -0
- package/dist/label.d.ts +16 -0
- package/dist/label.js +8 -0
- package/dist/lifecycle.d.ts +11 -0
- package/dist/lifecycle.js +91 -0
- package/dist/list-items.d.ts +38 -0
- package/dist/list-items.js +59 -0
- package/dist/list-text.d.ts +7 -0
- package/dist/list-text.js +15 -0
- package/dist/listbox.d.ts +273 -0
- package/dist/listbox.js +126 -0
- package/dist/menu.d.ts +678 -0
- package/dist/menu.js +607 -0
- package/dist/menubar-context.d.ts +5 -0
- package/dist/menubar-context.js +5 -0
- package/dist/menubar.d.ts +61 -0
- package/dist/menubar.js +48 -0
- package/dist/meter.d.ts +41 -0
- package/dist/meter.js +37 -0
- package/dist/navigation-menu.d.ts +228 -0
- package/dist/navigation-menu.js +195 -0
- package/dist/number-input.d.ts +176 -0
- package/dist/number-input.js +231 -0
- package/dist/number.d.ts +2 -0
- package/dist/number.js +39 -0
- package/dist/nuxt/entries.json +977 -0
- package/dist/nuxt/module.d.ts +18 -0
- package/dist/nuxt/module.js +31 -0
- package/dist/nuxt/registrations.d.ts +22 -0
- package/dist/nuxt/registrations.js +22 -0
- package/dist/observe.d.ts +2 -0
- package/dist/observe.js +7 -0
- package/dist/otp-input.d.ts +142 -0
- package/dist/otp-input.js +130 -0
- package/dist/overlays.d.ts +40 -0
- package/dist/overlays.js +118 -0
- package/dist/pagination.d.ts +201 -0
- package/dist/pagination.js +146 -0
- package/dist/password-input.d.ts +144 -0
- package/dist/password-input.js +134 -0
- package/dist/popover.d.ts +211 -0
- package/dist/popover.js +258 -0
- package/dist/popup.d.ts +60 -0
- package/dist/popup.js +89 -0
- package/dist/preferences.d.ts +44 -0
- package/dist/preferences.js +102 -0
- package/dist/primitive.d.ts +2 -0
- package/dist/primitive.js +11 -0
- package/dist/progress.d.ts +41 -0
- package/dist/progress.js +37 -0
- package/dist/radio.d.ts +164 -0
- package/dist/radio.js +145 -0
- package/dist/rating.d.ts +149 -0
- package/dist/rating.js +146 -0
- package/dist/renderless.d.ts +4 -0
- package/dist/renderless.js +28 -0
- package/dist/resizable.d.ts +54 -0
- package/dist/resizable.js +22 -0
- package/dist/scroll-area.d.ts +72 -0
- package/dist/scroll-area.js +77 -0
- package/dist/segmented-control.d.ts +151 -0
- package/dist/segmented-control.js +110 -0
- package/dist/segmented-input.d.ts +76 -0
- package/dist/segmented-input.js +115 -0
- package/dist/select.d.ts +458 -0
- package/dist/select.js +468 -0
- package/dist/separator.d.ts +14 -0
- package/dist/separator.js +8 -0
- package/dist/shortcuts.d.ts +32 -0
- package/dist/shortcuts.js +56 -0
- package/dist/slider.d.ts +65 -0
- package/dist/slider.js +194 -0
- package/dist/switch.d.ts +103 -0
- package/dist/switch.js +71 -0
- package/dist/tabs.d.ts +338 -0
- package/dist/tabs.js +27 -0
- package/dist/text-control.d.ts +89 -0
- package/dist/text-control.js +51 -0
- package/dist/text-match.d.ts +2 -0
- package/dist/text-match.js +7 -0
- package/dist/textarea.d.ts +106 -0
- package/dist/textarea.js +68 -0
- package/dist/time-input.d.ts +131 -0
- package/dist/time-input.js +32 -0
- package/dist/timeline.d.ts +81 -0
- package/dist/timeline.js +30 -0
- package/dist/toast-parts.d.ts +203 -0
- package/dist/toast-parts.js +270 -0
- package/dist/toast.d.ts +2 -0
- package/dist/toast.js +21 -0
- package/dist/toggle-props.d.ts +22 -0
- package/dist/toggle-props.js +14 -0
- package/dist/toggle.d.ts +199 -0
- package/dist/toggle.js +129 -0
- package/dist/token-input.d.ts +136 -0
- package/dist/token-input.js +214 -0
- package/dist/toolbar-context.d.ts +7 -0
- package/dist/toolbar-context.js +20 -0
- package/dist/toolbar.d.ts +120 -0
- package/dist/toolbar.js +77 -0
- package/dist/tooltip.d.ts +160 -0
- package/dist/tooltip.js +224 -0
- package/dist/tree.d.ts +300 -0
- package/dist/tree.js +209 -0
- package/dist/trigger-menu.d.ts +452 -0
- package/dist/trigger-menu.js +254 -0
- package/dist/use-primitive.d.ts +132 -0
- package/dist/use-primitive.js +462 -0
- package/dist/waterfall.d.ts +201 -0
- package/dist/waterfall.js +171 -0
- package/docs/README.md +89 -0
- package/docs/agents.md +1523 -0
- package/docs/components/accordion.md +1369 -0
- package/docs/components/alert-dialog.md +799 -0
- package/docs/components/autocomplete.md +1857 -0
- package/docs/components/avatar.md +272 -0
- package/docs/components/button.md +435 -0
- package/docs/components/calendar.md +1589 -0
- package/docs/components/carousel.md +1171 -0
- package/docs/components/checkbox.md +1008 -0
- package/docs/components/collapsible.md +536 -0
- package/docs/components/color-picker.md +706 -0
- package/docs/components/combobox.md +3504 -0
- package/docs/components/command.md +1481 -0
- package/docs/components/date-input.md +536 -0
- package/docs/components/date-picker.md +1244 -0
- package/docs/components/dialog.md +1397 -0
- package/docs/components/drawer.md +1166 -0
- package/docs/components/field.md +538 -0
- package/docs/components/file-input.md +611 -0
- package/docs/components/hover-card.md +505 -0
- package/docs/components/image-cropper.md +556 -0
- package/docs/components/input.md +306 -0
- package/docs/components/label.md +203 -0
- package/docs/components/listbox.md +1004 -0
- package/docs/components/menu.md +1229 -0
- package/docs/components/menubar.md +443 -0
- package/docs/components/meter.md +315 -0
- package/docs/components/navigation-menu.md +1523 -0
- package/docs/components/number-input.md +1029 -0
- package/docs/components/otp-input.md +512 -0
- package/docs/components/pagination.md +613 -0
- package/docs/components/password-input.md +649 -0
- package/docs/components/popover.md +1448 -0
- package/docs/components/preferences.md +208 -0
- package/docs/components/progress.md +423 -0
- package/docs/components/radio.md +785 -0
- package/docs/components/rating.md +416 -0
- package/docs/components/resizable.md +910 -0
- package/docs/components/scroll-area.md +915 -0
- package/docs/components/segmented-control.md +435 -0
- package/docs/components/select.md +2015 -0
- package/docs/components/separator.md +229 -0
- package/docs/components/slider.md +1084 -0
- package/docs/components/switch.md +565 -0
- package/docs/components/tabs.md +944 -0
- package/docs/components/textarea.md +299 -0
- package/docs/components/time-input.md +224 -0
- package/docs/components/timeline.md +654 -0
- package/docs/components/toast.md +1224 -0
- package/docs/components/toggle.md +500 -0
- package/docs/components/token-input.md +953 -0
- package/docs/components/toolbar.md +739 -0
- package/docs/components/tooltip.md +818 -0
- package/docs/components/tree.md +1306 -0
- package/docs/components/trigger-menu.md +1223 -0
- package/docs/components/waterfall.md +717 -0
- package/docs/controllers.md +71 -0
- package/docs/core.md +8027 -0
- package/docs/custom-parts.md +89 -0
- package/docs/first-component.md +83 -0
- package/docs/forms.md +122 -0
- package/docs/installation.md +72 -0
- package/docs/introduction.md +32 -0
- package/docs/lists-and-menus.md +122 -0
- package/docs/llms.txt +1502 -0
- package/docs/parts-and-composition.md +85 -0
- package/docs/popups.md +108 -0
- package/docs/rendering.md +56 -0
- package/docs/server-rendering.md +180 -0
- package/docs/state-and-events.md +100 -0
- package/docs/styling-and-animation.md +148 -0
- package/docs/utilities/async-options.md +348 -0
- package/docs/utilities/shortcuts.md +159 -0
- package/package.json +352 -3
|
@@ -0,0 +1,818 @@
|
|
|
1
|
+
# Tooltip
|
|
2
|
+
|
|
3
|
+
Name a control or add a short hint on hover and keyboard focus.
|
|
4
|
+
|
|
5
|
+
A tooltip names a control or adds a short hint when the pointer rests on it or keyboard focus reaches it. Keep it to a few words of plain text.
|
|
6
|
+
|
|
7
|
+
```vue title="basic.vue"
|
|
8
|
+
<script setup lang="ts">
|
|
9
|
+
import { BookmarkIcon } from "@lucide/vue"
|
|
10
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "@ui-sdk/vue/tooltip"
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<Tooltip default-open>
|
|
15
|
+
<TooltipTrigger aria-label="Add to library">
|
|
16
|
+
<BookmarkIcon aria-hidden="true" />
|
|
17
|
+
</TooltipTrigger>
|
|
18
|
+
<TooltipContent>Add to library</TooltipContent>
|
|
19
|
+
</Tooltip>
|
|
20
|
+
</template>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The tooltip starts open. Hover the button or reach it with Tab to show it again, and Escape closes it while focus stays on the button.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @ui-sdk/vue @ui-sdk/core
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Composition
|
|
32
|
+
|
|
33
|
+
Use the following composition to build a `Tooltip`:
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
Tooltip
|
|
37
|
+
├── TooltipTrigger
|
|
38
|
+
└── TooltipContent
|
|
39
|
+
├── TooltipArrow
|
|
40
|
+
└── TooltipShortcut
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Wrap the trigger and its hint in a tooltip. The arrow and the shortcut are optional.
|
|
44
|
+
|
|
45
|
+
The content has the `tooltip` role, and it's in the page from the start, hidden, so it names or describes its trigger before focus reaches it. It names a trigger without a name of its own, like a button with only an icon, and describes any other: one with text, an `aria-label` or a `title`. `type="label"` or `type="description"` overrides the guess. Keep it to plain text: a tooltip can't be focused, so links or buttons inside it can't be reached. For anything interactive, use a [Popover](./popover.md) or a [Hover Card](./hover-card.md).
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
Import the parts and put them together:
|
|
50
|
+
|
|
51
|
+
```vue
|
|
52
|
+
<script setup lang="ts">
|
|
53
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "@ui-sdk/vue/tooltip"
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<template>
|
|
57
|
+
<Tooltip>
|
|
58
|
+
<TooltipTrigger>Share</TooltipTrigger>
|
|
59
|
+
<TooltipContent>Anyone with the link can view</TooltipContent>
|
|
60
|
+
</Tooltip>
|
|
61
|
+
</template>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Side
|
|
65
|
+
|
|
66
|
+
`side` picks where the tooltip opens: `top` by default. It flips to the other side when there isn't room, and shifts along the trigger to stay on screen. `data-side` says where it landed.
|
|
67
|
+
|
|
68
|
+
```vue title="side.vue"
|
|
69
|
+
<script setup lang="ts">
|
|
70
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "@ui-sdk/vue/tooltip"
|
|
71
|
+
|
|
72
|
+
const sides = [
|
|
73
|
+
{ side: "top", label: "Top" },
|
|
74
|
+
{ side: "left", label: "Left" },
|
|
75
|
+
{ side: "right", label: "Right" },
|
|
76
|
+
{ side: "bottom", label: "Bottom" },
|
|
77
|
+
] as const
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<template>
|
|
81
|
+
<div data-slot="grid">
|
|
82
|
+
<Tooltip v-for="{ side, label } in sides" :key="side">
|
|
83
|
+
<TooltipTrigger>{{ label }}</TooltipTrigger>
|
|
84
|
+
<TooltipContent :side="side">Add to library</TooltipContent>
|
|
85
|
+
</Tooltip>
|
|
86
|
+
</div>
|
|
87
|
+
</template>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Hover Top, Left, Right and Bottom. Each tooltip opens on that side of its button, or flips into the middle when there isn't room.
|
|
91
|
+
|
|
92
|
+
Add a `TooltipArrow` to point at the trigger. It follows the side the tooltip lands on, including after a flip.
|
|
93
|
+
|
|
94
|
+
```vue
|
|
95
|
+
<TooltipContent>
|
|
96
|
+
<TooltipArrow />
|
|
97
|
+
Add to library
|
|
98
|
+
</TooltipContent>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Anchor
|
|
102
|
+
|
|
103
|
+
Position the tooltip against something other than the trigger with `anchor`: an element, a CSS selector, a point like `{ x, y }`, or anything with `getBoundingClientRect()`. Here a small help button inside a field shows its tooltip along the whole field.
|
|
104
|
+
|
|
105
|
+
```vue title="anchor.vue"
|
|
106
|
+
<script setup lang="ts">
|
|
107
|
+
import { InfoIcon } from "@lucide/vue"
|
|
108
|
+
import { Field, FieldLabel } from "@ui-sdk/vue/field"
|
|
109
|
+
import { Input } from "@ui-sdk/vue/input"
|
|
110
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "@ui-sdk/vue/tooltip"
|
|
111
|
+
import { useTemplateRef } from "vue"
|
|
112
|
+
|
|
113
|
+
const field = useTemplateRef<HTMLDivElement>("field")
|
|
114
|
+
</script>
|
|
115
|
+
|
|
116
|
+
<template>
|
|
117
|
+
<Field>
|
|
118
|
+
<FieldLabel>Webhook URL</FieldLabel>
|
|
119
|
+
<div ref="field" data-slot="row">
|
|
120
|
+
<Input placeholder="https://" />
|
|
121
|
+
<Tooltip>
|
|
122
|
+
<TooltipTrigger aria-label="About webhooks">
|
|
123
|
+
<InfoIcon aria-hidden="true" />
|
|
124
|
+
</TooltipTrigger>
|
|
125
|
+
<TooltipContent :anchor="field" side="bottom" align="start">
|
|
126
|
+
We send a POST request here for every new order.
|
|
127
|
+
</TooltipContent>
|
|
128
|
+
</Tooltip>
|
|
129
|
+
</div>
|
|
130
|
+
</Field>
|
|
131
|
+
</template>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Hover the help button. The tooltip opens below the Webhook URL field and lines up with its start, not with the button.
|
|
135
|
+
|
|
136
|
+
## Keyboard Shortcut
|
|
137
|
+
|
|
138
|
+
`shortcut` on the tooltip, like `"mod+s"`, is a hint for what the trigger's action is bound to, where `mod` is Command on Apple platforms and Control elsewhere. `TooltipShortcut` shows the keys for the platform, `⌘S` or `Ctrl+S`, hidden from screen readers, and the trigger gets `aria-keyshortcuts` so they hear it instead. A `TooltipShortcut` can show other keys with its own `shortcut`.
|
|
139
|
+
|
|
140
|
+
The tooltip doesn't bind the keys. Register the shortcut yourself with [`registerShortcut`](../utilities/shortcuts.md), as the example does, or use the `shortcut` of a component that binds keys, like a [Dialog](./dialog.md#keyboard-shortcut) trigger.
|
|
141
|
+
|
|
142
|
+
```vue title="shortcut.vue"
|
|
143
|
+
<script setup lang="ts">
|
|
144
|
+
import { SaveIcon } from "@lucide/vue"
|
|
145
|
+
import { registerShortcut } from "@ui-sdk/core/shortcuts"
|
|
146
|
+
import {
|
|
147
|
+
Tooltip,
|
|
148
|
+
TooltipContent,
|
|
149
|
+
TooltipShortcut,
|
|
150
|
+
TooltipTrigger,
|
|
151
|
+
} from "@ui-sdk/vue/tooltip"
|
|
152
|
+
import { onMounted, onUnmounted } from "vue"
|
|
153
|
+
import { useLog } from "./log"
|
|
154
|
+
|
|
155
|
+
const log = useLog()
|
|
156
|
+
const offs: (() => void)[] = []
|
|
157
|
+
|
|
158
|
+
onMounted(() => {
|
|
159
|
+
offs.push(
|
|
160
|
+
registerShortcut("mod+s", () => log("Saved")),
|
|
161
|
+
registerShortcut("mod+shift+e", () => log("Shared"))
|
|
162
|
+
)
|
|
163
|
+
})
|
|
164
|
+
onUnmounted(() => offs.forEach((off) => off()))
|
|
165
|
+
</script>
|
|
166
|
+
|
|
167
|
+
<template>
|
|
168
|
+
<div data-slot="row">
|
|
169
|
+
<Tooltip shortcut="mod+s">
|
|
170
|
+
<TooltipTrigger aria-label="Save" @click="log('Saved')">
|
|
171
|
+
<SaveIcon aria-hidden="true" />
|
|
172
|
+
</TooltipTrigger>
|
|
173
|
+
<TooltipContent>
|
|
174
|
+
Save
|
|
175
|
+
<TooltipShortcut />
|
|
176
|
+
</TooltipContent>
|
|
177
|
+
</Tooltip>
|
|
178
|
+
<Tooltip shortcut="mod+shift+e">
|
|
179
|
+
<TooltipTrigger @click="log('Shared')">Share</TooltipTrigger>
|
|
180
|
+
<TooltipContent>
|
|
181
|
+
Share with your team
|
|
182
|
+
<TooltipShortcut />
|
|
183
|
+
</TooltipContent>
|
|
184
|
+
</Tooltip>
|
|
185
|
+
</div>
|
|
186
|
+
</template>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Hover Save or Share to read its shortcut, then press the button or the keys. The console logs Saved or Shared.
|
|
190
|
+
|
|
191
|
+
## Disabled Buttons
|
|
192
|
+
|
|
193
|
+
A natively disabled button can't receive focus, and some browsers send it no pointer events, so its tooltip never shows. When the tooltip explains why an action is unavailable, use `aria-disabled="true"` instead and ignore the button's presses yourself. The button stays in the Tab order, screen readers announce it as dimmed, and the tooltip explains what's missing. `disabled` on the tooltip turns the explanation off once the button works.
|
|
194
|
+
|
|
195
|
+
```vue title="disabled-button.vue"
|
|
196
|
+
<script setup lang="ts">
|
|
197
|
+
import { Field, FieldLabel } from "@ui-sdk/vue/field"
|
|
198
|
+
import { Input } from "@ui-sdk/vue/input"
|
|
199
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "@ui-sdk/vue/tooltip"
|
|
200
|
+
import { computed, ref } from "vue"
|
|
201
|
+
import { useLog } from "./log"
|
|
202
|
+
|
|
203
|
+
const log = useLog()
|
|
204
|
+
const title = ref("")
|
|
205
|
+
const blocked = computed(() => !title.value.trim())
|
|
206
|
+
|
|
207
|
+
function publish() {
|
|
208
|
+
if (!blocked.value) {
|
|
209
|
+
log(`Published “${title.value.trim()}”`)
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
</script>
|
|
213
|
+
|
|
214
|
+
<template>
|
|
215
|
+
<div data-slot="stack">
|
|
216
|
+
<Field>
|
|
217
|
+
<FieldLabel>Post title</FieldLabel>
|
|
218
|
+
<Input v-model:value="title" />
|
|
219
|
+
</Field>
|
|
220
|
+
<Tooltip :disabled="!blocked">
|
|
221
|
+
<TooltipTrigger data-variant="solid" :aria-disabled="blocked || undefined" @click="publish">
|
|
222
|
+
Publish
|
|
223
|
+
</TooltipTrigger>
|
|
224
|
+
<TooltipContent side="right">Add a title to publish</TooltipContent>
|
|
225
|
+
</Tooltip>
|
|
226
|
+
</div>
|
|
227
|
+
</template>
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Hover or focus Publish to learn what's missing. Type a title, and Publish works and its tooltip goes away.
|
|
231
|
+
|
|
232
|
+
## Touch
|
|
233
|
+
|
|
234
|
+
Touch screens have no hover. A tap on a plain tooltip's trigger only presses it, and the tooltip stays closed, so don't hide anything important in a tooltip.
|
|
235
|
+
|
|
236
|
+
For an info button whose only job is the tip, add `toggleable`: pressing the trigger opens and closes the tooltip, with a finger, a mouse or the keyboard, and its text is announced when a press opens it. An outside press or Escape closes it too.
|
|
237
|
+
|
|
238
|
+
```vue title="toggleable.vue"
|
|
239
|
+
<script setup lang="ts">
|
|
240
|
+
import { InfoIcon } from "@lucide/vue"
|
|
241
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "@ui-sdk/vue/tooltip"
|
|
242
|
+
</script>
|
|
243
|
+
|
|
244
|
+
<template>
|
|
245
|
+
<div data-slot="row">
|
|
246
|
+
<span data-slot="label">Storage</span>
|
|
247
|
+
<Tooltip toggleable>
|
|
248
|
+
<TooltipTrigger aria-label="About storage" data-size="sm">
|
|
249
|
+
<InfoIcon aria-hidden="true" />
|
|
250
|
+
</TooltipTrigger>
|
|
251
|
+
<TooltipContent>Files in the trash still use storage.</TooltipContent>
|
|
252
|
+
</Tooltip>
|
|
253
|
+
<span data-slot="hint">12.4 of 15 GB used</span>
|
|
254
|
+
</div>
|
|
255
|
+
</template>
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Press the info button to open the tip, including on a touch screen. Press it again or anywhere else to close it.
|
|
259
|
+
|
|
260
|
+
## Keep Open on Press
|
|
261
|
+
|
|
262
|
+
Pressing the trigger closes the tooltip, so it doesn't cover what the press changed, and it stays closed until the pointer leaves. `:close-on-press="false"` keeps it open, like for a copy button whose tooltip turns into "Copied".
|
|
263
|
+
|
|
264
|
+
```vue title="copy.vue"
|
|
265
|
+
<script setup lang="ts">
|
|
266
|
+
import { CheckIcon, CopyIcon } from "@lucide/vue"
|
|
267
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "@ui-sdk/vue/tooltip"
|
|
268
|
+
import { ref } from "vue"
|
|
269
|
+
|
|
270
|
+
const command = "npm install @ui-sdk/vue"
|
|
271
|
+
const copied = ref(false)
|
|
272
|
+
|
|
273
|
+
function copy() {
|
|
274
|
+
navigator.clipboard?.writeText(command).catch(() => {})
|
|
275
|
+
copied.value = true
|
|
276
|
+
}
|
|
277
|
+
</script>
|
|
278
|
+
|
|
279
|
+
<template>
|
|
280
|
+
<div data-slot="row">
|
|
281
|
+
<code>{{ command }}</code>
|
|
282
|
+
<Tooltip
|
|
283
|
+
:close-on-press="false"
|
|
284
|
+
@open-change-complete="(open) => !open && (copied = false)"
|
|
285
|
+
>
|
|
286
|
+
<TooltipTrigger :aria-label="copied ? 'Copied' : 'Copy'" @click="copy">
|
|
287
|
+
<CheckIcon v-if="copied" aria-hidden="true" />
|
|
288
|
+
<CopyIcon v-else aria-hidden="true" />
|
|
289
|
+
</TooltipTrigger>
|
|
290
|
+
<TooltipContent>{{ copied ? "Copied" : "Copy" }}</TooltipContent>
|
|
291
|
+
</Tooltip>
|
|
292
|
+
</div>
|
|
293
|
+
</template>
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Hover the copy button and press it. The tooltip stays open and changes to Copied.
|
|
297
|
+
|
|
298
|
+
## Truncated Text
|
|
299
|
+
|
|
300
|
+
To show a tooltip only when text is cut off, cancel the open in `@open-change` when the text fits. Compare `scrollWidth` with `clientWidth` in the callback. The tooltip repeats the name, so `type="label"` keeps screen readers from hearing it twice.
|
|
301
|
+
|
|
302
|
+
```vue title="truncated.vue"
|
|
303
|
+
<script setup lang="ts">
|
|
304
|
+
import { FileIcon } from "@lucide/vue"
|
|
305
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "@ui-sdk/vue/tooltip"
|
|
306
|
+
|
|
307
|
+
const files = [
|
|
308
|
+
"Quarterly report, final revised version for the board.pdf",
|
|
309
|
+
"Notes.txt",
|
|
310
|
+
"Design review recording, October 2nd.mp4",
|
|
311
|
+
"Budget.xlsx",
|
|
312
|
+
]
|
|
313
|
+
|
|
314
|
+
const names = new Map<string, HTMLElement>()
|
|
315
|
+
|
|
316
|
+
function fits(file: string) {
|
|
317
|
+
const span = names.get(file)
|
|
318
|
+
return !!span && span.scrollWidth <= span.clientWidth
|
|
319
|
+
}
|
|
320
|
+
</script>
|
|
321
|
+
|
|
322
|
+
<template>
|
|
323
|
+
<ul>
|
|
324
|
+
<li v-for="file in files" :key="file">
|
|
325
|
+
<Tooltip
|
|
326
|
+
type="label"
|
|
327
|
+
@open-change="(open, details) => open && fits(file) && details.cancel()"
|
|
328
|
+
>
|
|
329
|
+
<TooltipTrigger>
|
|
330
|
+
<FileIcon aria-hidden="true" />
|
|
331
|
+
<span :ref="(el) => el && names.set(file, el as HTMLElement)">{{
|
|
332
|
+
file
|
|
333
|
+
}}</span>
|
|
334
|
+
</TooltipTrigger>
|
|
335
|
+
<TooltipContent>{{ file }}</TooltipContent>
|
|
336
|
+
</Tooltip>
|
|
337
|
+
</li>
|
|
338
|
+
</ul>
|
|
339
|
+
</template>
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Hover or focus each file. Only names that are cut off open a tooltip.
|
|
343
|
+
|
|
344
|
+
## Controlled
|
|
345
|
+
|
|
346
|
+
Bind `v-model:open`, or pass `open` and update it in `@open-change`. Every change carries a [reason](#reasons), like `trigger-hover`, `trigger-focus`, `trigger-press`, `escape-key` or `outside-press`. Call `details.cancel()` to stop it. To open the tooltip from anywhere, like a step in a guided tour, use a [controller](#controller).
|
|
347
|
+
|
|
348
|
+
```vue title="controlled.vue"
|
|
349
|
+
<script setup lang="ts">
|
|
350
|
+
import { CheckIcon } from "@lucide/vue"
|
|
351
|
+
import type { ChangeDetails } from "@ui-sdk/core"
|
|
352
|
+
import { Checkbox, CheckboxIndicator } from "@ui-sdk/vue/checkbox"
|
|
353
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "@ui-sdk/vue/tooltip"
|
|
354
|
+
import { ref } from "vue"
|
|
355
|
+
import { useLog } from "./log"
|
|
356
|
+
|
|
357
|
+
const log = useLog()
|
|
358
|
+
const open = ref(false)
|
|
359
|
+
const controls = ref<HTMLElement | null>(null)
|
|
360
|
+
|
|
361
|
+
function onOpenChange(next: boolean, details: ChangeDetails) {
|
|
362
|
+
const target = details.event?.target
|
|
363
|
+
const inControls = target instanceof Node && controls.value?.contains(target)
|
|
364
|
+
if (inControls && details.reason !== "escape-key") {
|
|
365
|
+
return details.cancel()
|
|
366
|
+
}
|
|
367
|
+
log(`${next ? "Opened" : "Closed"} (${details.reason})`)
|
|
368
|
+
}
|
|
369
|
+
</script>
|
|
370
|
+
|
|
371
|
+
<template>
|
|
372
|
+
<div data-slot="stack">
|
|
373
|
+
<div ref="controls" data-slot="controls">
|
|
374
|
+
<label data-slot="label">
|
|
375
|
+
<Checkbox v-model:checked="open">
|
|
376
|
+
<CheckboxIndicator>
|
|
377
|
+
<CheckIcon aria-hidden="true" />
|
|
378
|
+
</CheckboxIndicator>
|
|
379
|
+
</Checkbox>
|
|
380
|
+
Open
|
|
381
|
+
</label>
|
|
382
|
+
</div>
|
|
383
|
+
<Tooltip v-model:open="open" @open-change="onOpenChange">
|
|
384
|
+
<TooltipTrigger>Export</TooltipTrigger>
|
|
385
|
+
<TooltipContent>Download as CSV</TooltipContent>
|
|
386
|
+
</Tooltip>
|
|
387
|
+
</div>
|
|
388
|
+
</template>
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Check Open, or hover Export. The console logs each change and its reason.
|
|
392
|
+
|
|
393
|
+
## Shared
|
|
394
|
+
|
|
395
|
+
A toolbar, a chart or a long list can share one tooltip instead of rendering one per item. Connect the triggers and the tooltip to one `createTooltipController<Payload>()`, and the triggers can sit anywhere on the page. Each trigger passes a `payload`, here its label, and the content reads it from its state, since every part's default slot receives its state. A template can't pass a type argument, so `TooltipContent<string>` in the script makes a content part that types the payload. The content renders before the first open, so handle an `undefined` payload.
|
|
396
|
+
|
|
397
|
+
Only the trigger that opened the tooltip is described by it, so give each trigger a name of its own, like an `aria-label`. The controller's `open()` takes a payload and an `anchor` too, and on an open tooltip, `open({ payload })` replaces the payload, like another trigger taking it over. `@payload-change` reports each change.
|
|
398
|
+
|
|
399
|
+
```vue title="shared.vue"
|
|
400
|
+
<script setup lang="ts">
|
|
401
|
+
import { BoldIcon, ItalicIcon, UnderlineIcon } from "@lucide/vue"
|
|
402
|
+
import {
|
|
403
|
+
createTooltipController,
|
|
404
|
+
Tooltip,
|
|
405
|
+
TooltipContent,
|
|
406
|
+
TooltipTrigger,
|
|
407
|
+
} from "@ui-sdk/vue/tooltip"
|
|
408
|
+
|
|
409
|
+
const formats = [
|
|
410
|
+
{ icon: BoldIcon, label: "Bold" },
|
|
411
|
+
{ icon: ItalicIcon, label: "Italic" },
|
|
412
|
+
{ icon: UnderlineIcon, label: "Underline" },
|
|
413
|
+
]
|
|
414
|
+
|
|
415
|
+
const tooltip = createTooltipController<string>()
|
|
416
|
+
const LabelTooltipContent = TooltipContent<string>
|
|
417
|
+
</script>
|
|
418
|
+
|
|
419
|
+
<template>
|
|
420
|
+
<div data-slot="row" role="group" aria-label="Formatting">
|
|
421
|
+
<TooltipTrigger
|
|
422
|
+
v-for="format in formats"
|
|
423
|
+
:key="format.label"
|
|
424
|
+
:controller="tooltip"
|
|
425
|
+
:payload="format.label"
|
|
426
|
+
:aria-label="format.label"
|
|
427
|
+
>
|
|
428
|
+
<component :is="format.icon" aria-hidden="true" />
|
|
429
|
+
</TooltipTrigger>
|
|
430
|
+
<Tooltip :controller="tooltip">
|
|
431
|
+
<LabelTooltipContent v-slot="{ state }">{{
|
|
432
|
+
state.payload
|
|
433
|
+
}}</LabelTooltipContent>
|
|
434
|
+
</Tooltip>
|
|
435
|
+
</div>
|
|
436
|
+
</template>
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
Move along Bold, Italic and Underline. One tooltip follows the pointer and shows each button's label.
|
|
440
|
+
|
|
441
|
+
## Animation
|
|
442
|
+
|
|
443
|
+
The content has `data-starting-style` while it opens and `data-ending-style` while it closes. Transition from those states, and the tooltip stays mounted until its exit finishes. Put `transform-origin: var(--transform-origin)` on the content so it grows out of its trigger. A tooltip that opens at once, as the next one in a group does, gets `data-instant`, so skip the transition there.
|
|
444
|
+
|
|
445
|
+
```css
|
|
446
|
+
[data-slot="tooltip-content"] {
|
|
447
|
+
transform-origin: var(--transform-origin);
|
|
448
|
+
transition:
|
|
449
|
+
opacity 150ms ease-out,
|
|
450
|
+
scale 150ms ease-out;
|
|
451
|
+
|
|
452
|
+
&:is([data-starting-style], [data-ending-style]) {
|
|
453
|
+
opacity: 0;
|
|
454
|
+
scale: 0.9;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
&[data-instant] {
|
|
458
|
+
transition: none;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
For people who ask for less motion, drop the scale in a `prefers-reduced-motion` query and keep the fade. `@open-change-complete` runs once the tooltip has finished opening or closing, after any animation, with the new open state.
|
|
464
|
+
|
|
465
|
+
```vue title="animation.vue"
|
|
466
|
+
<script setup lang="ts">
|
|
467
|
+
import { ArchiveIcon } from "@lucide/vue"
|
|
468
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "@ui-sdk/vue/tooltip"
|
|
469
|
+
import { useLog } from "./log"
|
|
470
|
+
|
|
471
|
+
const log = useLog()
|
|
472
|
+
</script>
|
|
473
|
+
|
|
474
|
+
<template>
|
|
475
|
+
<Tooltip
|
|
476
|
+
@open-change="(open) => log(open ? 'Opening' : 'Closing')"
|
|
477
|
+
@open-change-complete="(open) => log(open ? 'Open' : 'Closed')"
|
|
478
|
+
>
|
|
479
|
+
<TooltipTrigger aria-label="Archive">
|
|
480
|
+
<ArchiveIcon aria-hidden="true" />
|
|
481
|
+
</TooltipTrigger>
|
|
482
|
+
<TooltipContent>Archive</TooltipContent>
|
|
483
|
+
</Tooltip>
|
|
484
|
+
</template>
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
Hover Archive, then move away. The tooltip grows out of the button and fades, and the console logs Opening, Open, Closing and Closed.
|
|
488
|
+
|
|
489
|
+
## Delay and Grouping
|
|
490
|
+
|
|
491
|
+
`delay` is how long the pointer rests on the trigger before the tooltip opens, 600 milliseconds by default. `close-delay` is how long it stays once the pointer leaves the trigger and the tooltip, 0 by default. Keyboard focus opens it at once.
|
|
492
|
+
|
|
493
|
+
Tooltips group without a provider. Once one is open, or was a moment ago, hovering the next opens it at once, and only one is open at a time, so moving along a toolbar reads like one tooltip that follows the pointer. A tooltip that opened at once gets `data-instant`, so it can skip its animation.
|
|
494
|
+
|
|
495
|
+
`disabled` stops a tooltip from opening, while its trigger keeps working.
|
|
496
|
+
|
|
497
|
+
```vue
|
|
498
|
+
<Tooltip :delay="300" :close-delay="150" :disabled="!showHints">
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
## Offset
|
|
502
|
+
|
|
503
|
+
`side-offset` is the gap to the trigger, 4 pixels by default. `align-offset` shifts along it, `align` lines it up with the start, center or end of the trigger, and `collision-padding` is the space kept from the edges of the window.
|
|
504
|
+
|
|
505
|
+
```vue
|
|
506
|
+
<TooltipContent
|
|
507
|
+
align="start"
|
|
508
|
+
:side-offset="8"
|
|
509
|
+
:align-offset="4"
|
|
510
|
+
:collision-padding="16"
|
|
511
|
+
/>
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
## Container
|
|
515
|
+
|
|
516
|
+
Tooltips render in place and show in the top layer, so no ancestor clips or covers them. `container` renders the tooltip somewhere else, for iframes, shadow roots or a specific stacking context. See the shared [popup guide](../popups.md).
|
|
517
|
+
|
|
518
|
+
```vue
|
|
519
|
+
<TooltipContent :container="shadowRoot" />
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
## Custom Rendering
|
|
523
|
+
|
|
524
|
+
Every part takes a `#render` slot, which receives the props to bind and the part's state. See [Parts and Composition](../parts-and-composition.md) for prop merging and state-based rendering.
|
|
525
|
+
|
|
526
|
+
```vue title="custom-rendering.vue"
|
|
527
|
+
<script setup lang="ts">
|
|
528
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "@ui-sdk/vue/tooltip"
|
|
529
|
+
</script>
|
|
530
|
+
|
|
531
|
+
<template>
|
|
532
|
+
<Tooltip>
|
|
533
|
+
<TooltipTrigger data-variant="link">
|
|
534
|
+
<template #render="{ props }">
|
|
535
|
+
<a v-bind="props" href="https://example.com/changelog">Changelog</a>
|
|
536
|
+
</template>
|
|
537
|
+
</TooltipTrigger>
|
|
538
|
+
<TooltipContent>See what's new in 2.0</TooltipContent>
|
|
539
|
+
</Tooltip>
|
|
540
|
+
</template>
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
Hover Changelog. The trigger renders as a link, and its tooltip says where it goes.
|
|
544
|
+
|
|
545
|
+
A button can be a tooltip's trigger and another component's trigger at once. Render the tooltip's trigger as a `PopoverTrigger`, and the button opens the popover and is named by the tooltip:
|
|
546
|
+
|
|
547
|
+
```vue
|
|
548
|
+
<Popover>
|
|
549
|
+
<Tooltip>
|
|
550
|
+
<TooltipTrigger>
|
|
551
|
+
<template #render="{ props }">
|
|
552
|
+
<PopoverTrigger v-bind="props">
|
|
553
|
+
<BellIcon aria-hidden="true" />
|
|
554
|
+
</PopoverTrigger>
|
|
555
|
+
</template>
|
|
556
|
+
</TooltipTrigger>
|
|
557
|
+
<TooltipContent>Notifications</TooltipContent>
|
|
558
|
+
</Tooltip>
|
|
559
|
+
<PopoverContent>...</PopoverContent>
|
|
560
|
+
</Popover>
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
## Styling
|
|
564
|
+
|
|
565
|
+
Use `data-side` and `data-align` to style the content and arrow for where they landed, and `data-instant` to skip the animation of a tooltip that opened at once. The trigger gets no state attributes of its own, since it's often another component's trigger too, like a menu's. Put `transform-origin: var(--transform-origin)` on the content so it scales from the trigger.
|
|
566
|
+
|
|
567
|
+
Each part has a `data-slot`, such as `tooltip-content`, and its state attributes are listed under [Data Attributes](#data-attributes).
|
|
568
|
+
|
|
569
|
+
### TooltipContent
|
|
570
|
+
- `--anchor-width`: Width of the anchor, usually the trigger. Use it to match widths.
|
|
571
|
+
- `--anchor-height`: Height of the anchor.
|
|
572
|
+
- `--available-width`: Space beside the popup, up to the viewport edge. Not inherited either.
|
|
573
|
+
- `--available-height`: Space between the anchor and the viewport edge. Use it for max-height. Not inherited, so a child that needs it copies it on the popup, like `[--list-height:var(--available-height)]`, and reads `max-h-(--list-height)`. The first popup registers both names for the whole page with `CSS.registerProperty`, so they don't inherit anywhere. A page that needs them to inherit calls it first, with `inherits: true`. An `@property` rule can't, since a registration in script wins.
|
|
574
|
+
- `--transform-origin`: The point on the anchor the popup opens from. Use it to scale from the right place.
|
|
575
|
+
- `--arrow-offset`: Where the anchor's center falls along the popup's edge, kept `arrowPadding` from the corners. Position a ::before arrow with it.
|
|
576
|
+
|
|
577
|
+
## Data Attributes
|
|
578
|
+
|
|
579
|
+
`TooltipTrigger` and `TooltipShortcut` have no state attributes.
|
|
580
|
+
|
|
581
|
+
### TooltipContent
|
|
582
|
+
`[data-slot="tooltip-content"]`
|
|
583
|
+
|
|
584
|
+
- `data-closed`: Present while the tooltip is closed, including while it animates out.
|
|
585
|
+
- `data-open`: Present while the tooltip is open.
|
|
586
|
+
- `data-starting-style`: Present for the first frame. Style the state you animate from.
|
|
587
|
+
- `data-ending-style`: Present while the tooltip animates out. Style the state you animate to.
|
|
588
|
+
|
|
589
|
+
### TooltipArrow
|
|
590
|
+
`[data-slot="tooltip-arrow"]`
|
|
591
|
+
|
|
592
|
+
- `data-closed`: Present while the tooltip is closed, including while it animates out.
|
|
593
|
+
- `data-open`: Present while the tooltip is open.
|
|
594
|
+
|
|
595
|
+
## API Reference
|
|
596
|
+
|
|
597
|
+
Props are the same as below, and callbacks are events.
|
|
598
|
+
|
|
599
|
+
### Tooltip
|
|
600
|
+
|
|
601
|
+
- `container?` (`DocumentFragment | Element | null`): Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
|
|
602
|
+
- `open?` (`boolean`): Whether the tooltip is open. Pass it to control the tooltip.
|
|
603
|
+
- `defaultOpen?` (`boolean`): Whether the tooltip starts open, when uncontrolled.
|
|
604
|
+
- `@open-change` (`((open: boolean, details: ChangeDetails<TooltipOpenChangeReason>) => void)`): Runs when the tooltip wants to open or close. `details.reason` says why, and `details.cancel()` stops it.
|
|
605
|
+
- `@open-change-complete` (`((open: boolean) => void)`): Runs once the tooltip has finished opening or closing, after any animation.
|
|
606
|
+
- `@payload-change` (`((payload: unknown, details: ChangeDetails<TooltipPayloadChangeReason>) => void)`): Runs when the payload the content shows changes: a trigger with another payload opens the tooltip, or takes the open tooltip over, which fires no `@open-change`, and so does a controller's `open({ payload })` on the open tooltip. `details.cancel()` keeps the previous payload.
|
|
607
|
+
- `delay?` (`number`): Milliseconds the pointer rests on the trigger before the tooltip opens. While another tooltip is open, or was a moment ago, the next one opens at once, without a provider.
|
|
608
|
+
- `closeDelay?` (`number`): Milliseconds before the tooltip closes once the pointer leaves the trigger and the tooltip.
|
|
609
|
+
- `disabled?` (`boolean`): Stops the tooltip from opening. The trigger keeps working.
|
|
610
|
+
- `toggleable?` (`boolean`): Whether pressing the trigger opens and closes the tooltip, so touch screens can show it too. For info buttons whose only job is the tip. The text is announced when a press opens it.
|
|
611
|
+
- `closeOnPress?` (`boolean`): Whether pressing the trigger closes the tooltip. Set it to `false` to keep it open, like for a copy button whose tooltip turns into "Copied".
|
|
612
|
+
- `type?` (`"description" | "label"`): Whether the tooltip names its trigger (`"label"`) or adds a description to it (`"description"`). By default it names a trigger that has no name of its own, like an icon button, and describes any other.
|
|
613
|
+
- `shortcut?` (`string`): The keyboard shortcut of what the trigger does, like `"mod+s"`, as a hint. A `TooltipShortcut` shows it, and the trigger gets `aria-keyshortcuts`. It doesn't bind the keys: the trigger's own `shortcut`, or `registerShortcut`, does.
|
|
614
|
+
- `controller?` (`PopupController<any, TooltipOpenChangeReason, {}, string, TooltipPayloadChangeReason>`): Opens, closes and inspects the tooltip from anywhere, and connects triggers outside it. Create one with `createTooltipController()`.
|
|
615
|
+
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
|
|
616
|
+
|
|
617
|
+
### TooltipTrigger
|
|
618
|
+
|
|
619
|
+
A trigger outside the tooltip also takes `controller`.
|
|
620
|
+
|
|
621
|
+
- `payload?` (`unknown`): Data for the content to render when this trigger opens the tooltip, like the row it belongs to.
|
|
622
|
+
- `controller?` (`PopupController<any, TooltipOpenChangeReason, {}, string, TooltipPayloadChangeReason>`): Connects a trigger outside the tooltip, like one per table row, to the tooltip with this controller.
|
|
623
|
+
|
|
624
|
+
### TooltipContent
|
|
625
|
+
|
|
626
|
+
- `side?` (`Side`): Which side of the anchor the popup opens on. Flips to the other side when there isn't room. Which side of the trigger the tooltip opens on.
|
|
627
|
+
- `align?` (`Align`): How the popup lines up with the anchor along that side. `start` and `end` follow the reading direction. How the tooltip lines up with the trigger along that side.
|
|
628
|
+
- `sideOffset?` (`number`): Gap between the anchor and the popup, in pixels. Gap between the trigger and the tooltip, in pixels.
|
|
629
|
+
- `alignOffset?` (`number`): Shift along the anchor, in pixels. Shift along the trigger, in pixels.
|
|
630
|
+
- `collisionPadding?` (`number`): Space to keep from the viewport edges, in pixels.
|
|
631
|
+
- `arrowPadding?` (`number`): Space to keep between the arrow and the popup's corners, in pixels.
|
|
632
|
+
- `anchor?` (`string | Anchor | null`): Positions the popup against this instead of its trigger: an element, a CSS selector, a point like `{ x, y }`, or anything with `getBoundingClientRect()`. It's read on every check, so it can move. A controller's `open({ anchor })` wins for that open.
|
|
633
|
+
- `container?` (`DocumentFragment | Element | null`): Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
|
|
634
|
+
|
|
635
|
+
### TooltipArrow
|
|
636
|
+
|
|
637
|
+
Points at the trigger from the side the tooltip landed on. Renders a `div`.
|
|
638
|
+
|
|
639
|
+
### TooltipShortcut
|
|
640
|
+
|
|
641
|
+
- `shortcut?` (`string`): The keys to show. By default, the tooltip's `shortcut`.
|
|
642
|
+
|
|
643
|
+
### State
|
|
644
|
+
|
|
645
|
+
What render functions, state-based class names and slots receive, per part.
|
|
646
|
+
|
|
647
|
+
`TooltipTrigger`:
|
|
648
|
+
|
|
649
|
+
- `open` (`boolean`): Whether the tooltip is open from this trigger.
|
|
650
|
+
|
|
651
|
+
`TooltipContent`:
|
|
652
|
+
|
|
653
|
+
- `open` (`boolean`): Whether the tooltip is open. False while it animates out.
|
|
654
|
+
- `instant` (`boolean`): Whether it opened at once, because another tooltip was open a moment ago. Animations can skip.
|
|
655
|
+
- `payload` (`Payload | undefined`): The payload of the last open, from the trigger that opened it or a controller, typed as the controller's `Payload`.
|
|
656
|
+
|
|
657
|
+
`TooltipArrow`:
|
|
658
|
+
|
|
659
|
+
- `open` (`boolean`): Whether the tooltip is open. False as soon as it starts closing, while it still animates out.
|
|
660
|
+
|
|
661
|
+
`TooltipShortcut`:
|
|
662
|
+
|
|
663
|
+
- `text` (`string`): The shortcut formatted for this platform: `⌘S` on Apple platforms and `Ctrl+S` elsewhere. Empty without one.
|
|
664
|
+
|
|
665
|
+
### Reasons
|
|
666
|
+
|
|
667
|
+
`details.reason` says why the tooltip opened or closed.
|
|
668
|
+
|
|
669
|
+
- `trigger-hover` (`PointerEvent`): The pointer rested on a trigger, or left it, with hover opening.
|
|
670
|
+
- `trigger-focus` (`FocusEvent`): Keyboard focus reached a trigger that opens on focus, like a tooltip's.
|
|
671
|
+
- `trigger-press` (`MouseEvent | KeyboardEvent | TouchEvent`): Click, tap, Enter or Space on the part that opens, closes or toggles. Arrow keys that open a menu or submenu count too. A tap on a combobox's input that opens a sheet reports its `touchend`.
|
|
672
|
+
- `focus-out` (`KeyboardEvent | FocusEvent`): Focus left the layer, or Tab moved it out.
|
|
673
|
+
- `escape-key` (`KeyboardEvent`): Escape, or a submenu's close key (ArrowLeft in left-to-right layouts).
|
|
674
|
+
- `close-press` (`MouseEvent | KeyboardEvent | SubmitEvent`): A Close part was pressed, or a form with `method="dialog"` was submitted.
|
|
675
|
+
- `outside-press` (`MouseEvent`): A press outside the layer.
|
|
676
|
+
- `window-blur` (`FocusEvent`): The window lost focus.
|
|
677
|
+
- `back` (`Event`): Going back: the Android back button or gesture, or Backspace in an empty command input, which returns to the previous page.
|
|
678
|
+
- `imperative` (`none`): A controller or `api` call, or a property set on a web component.
|
|
679
|
+
|
|
680
|
+
For a payload change, it says what opened the tooltip or took it over.
|
|
681
|
+
|
|
682
|
+
- `trigger-hover` (`PointerEvent`): The pointer rested on a trigger, or left it, with hover opening.
|
|
683
|
+
- `trigger-focus` (`FocusEvent`): Keyboard focus reached a trigger that opens on focus, like a tooltip's.
|
|
684
|
+
- `trigger-press` (`MouseEvent | KeyboardEvent | TouchEvent`): Click, tap, Enter or Space on the part that opens, closes or toggles. Arrow keys that open a menu or submenu count too. A tap on a combobox's input that opens a sheet reports its `touchend`.
|
|
685
|
+
- `imperative` (`none`): A controller or `api` call, or a property set on a web component.
|
|
686
|
+
|
|
687
|
+
### Controller
|
|
688
|
+
|
|
689
|
+
Create one with `createTooltipController<Payload>()` and pass it as `controller`, to the tooltip and to any
|
|
690
|
+
triggers outside it. `Payload` is the type of the data triggers and `open()` pass.
|
|
691
|
+
|
|
692
|
+
Every write method takes an optional `{ reason, event }`, passed to `@open-change`.
|
|
693
|
+
|
|
694
|
+
- `isOpen()` (`() => boolean`): Whether it's open. False as soon as it starts closing, while it still animates out.
|
|
695
|
+
- `setOpen(open, options?)` (`(open: boolean, options?: PopupChangeOptions<TooltipOpenChangeReason> | undefined) => boolean`): Opens or closes it. Returns false when the change was canceled or it was already open or closed.
|
|
696
|
+
- `open(options?)` (`(options?: (PopupChangeOptions<TooltipPayloadChangeReason> & { payload?: Payload | undefined; anchor?: Anchor | undefined; signal?: AbortSignal | undefined; }) | undefined) => Promise<...>`): Opens it, and resolves once it closes, with why, how and any return value. Resolves exactly once and never rejects: on the next close from any source, when `signal` aborts, or with reason `"unmount"` when the component leaves the page.
|
|
697
|
+
- `close(options?)` (`(options?: (PopupChangeOptions<TooltipOpenChangeReason> & { returnValue?: string | undefined; }) | undefined) => boolean`): Closes it. `returnValue` is passed to the promise `open()` returned. Returns false when the close was canceled or it was already closed.
|
|
698
|
+
- `toggle(options?)` (`(options?: PopupChangeOptions<TooltipOpenChangeReason> | undefined) => boolean`): Opens it when it's closed, and closes it when it's open. Returns false when the change was canceled.
|
|
699
|
+
- `getPayload()` (`() => Payload | undefined`): The payload of the last open, from a controller or the trigger that opened it.
|
|
700
|
+
- `focus()` (`() => void`): Moves focus to the trigger that opened it last, or the first trigger.
|
|
701
|
+
|
|
702
|
+
### Events
|
|
703
|
+
|
|
704
|
+
Events get the new state first, then the details. `v-model` only updates when `@open-change` wasn't canceled.
|
|
705
|
+
|
|
706
|
+
| Binding | On | Receives |
|
|
707
|
+
| ----------------------- | --------- | --------------------------------------------------------------------------- |
|
|
708
|
+
| `v-model:open` | `Tooltip` | Whether the tooltip is open |
|
|
709
|
+
| `@open-change` | `Tooltip` | `(open, details)`: the new state, and the [reason](#reasons) |
|
|
710
|
+
| `@open-change-complete` | `Tooltip` | `(open)`, after the animation |
|
|
711
|
+
| `@payload-change` | `Tooltip` | `(payload, details)`: the content's new payload, and the [reason](#reasons) |
|
|
712
|
+
|
|
713
|
+
## Accessibility
|
|
714
|
+
|
|
715
|
+
The trigger is named or described by the tooltip, following the [WAI-ARIA tooltip pattern](https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/). It opens on hover and on keyboard focus, and stays open while the pointer moves onto it.
|
|
716
|
+
|
|
717
|
+
### Keyboard
|
|
718
|
+
|
|
719
|
+
| Key | Does |
|
|
720
|
+
| ------------ | ---------------------------------------------------------------------------------------------- |
|
|
721
|
+
| Tab | Focus on the trigger opens the tooltip at once; focus leaving it closes the tooltip |
|
|
722
|
+
| Escape | Closes the tooltip and leaves focus on the trigger, without closing a dialog or menu around it |
|
|
723
|
+
| Enter, Space | Presses the trigger and closes the tooltip; on a `toggleable` trigger, opens and closes it |
|
|
724
|
+
|
|
725
|
+
### Tested Behavior
|
|
726
|
+
|
|
727
|
+
Every line below is an automated test.
|
|
728
|
+
|
|
729
|
+
**Pointer**
|
|
730
|
+
|
|
731
|
+
- Resting the pointer on the trigger opens the tooltip.
|
|
732
|
+
- The tooltip waits for its delay before opening.
|
|
733
|
+
- Leaving the trigger before the delay keeps the tooltip closed.
|
|
734
|
+
- Moving the pointer away closes the tooltip.
|
|
735
|
+
- The pointer can move onto the tooltip without closing it.
|
|
736
|
+
- Opening on hover leaves focus where it was.
|
|
737
|
+
- Pressing the trigger closes the tooltip and runs the button.
|
|
738
|
+
- After a press, the tooltip stays closed until the pointer comes back.
|
|
739
|
+
|
|
740
|
+
**Keyboard**
|
|
741
|
+
|
|
742
|
+
- Keyboard focus on the trigger opens the tooltip.
|
|
743
|
+
- Focus leaving the trigger closes the tooltip.
|
|
744
|
+
- Escape closes the tooltip and leaves focus on the trigger.
|
|
745
|
+
- Escape closes a tooltip opened by hover.
|
|
746
|
+
- Tab through the toolbar shows each tooltip in turn.
|
|
747
|
+
- A click that focuses the trigger doesn't open the tooltip from focus.
|
|
748
|
+
|
|
749
|
+
**Several tooltips**
|
|
750
|
+
|
|
751
|
+
- Only one tooltip is open at a time.
|
|
752
|
+
- Once the pointer has been away a while, the delay applies again.
|
|
753
|
+
|
|
754
|
+
**Positioning**
|
|
755
|
+
|
|
756
|
+
- The tooltip opens above the trigger.
|
|
757
|
+
- The tooltip flips below the trigger when there is no room above.
|
|
758
|
+
- The tooltip opens on the requested side.
|
|
759
|
+
- The arrow points at the middle of the trigger.
|
|
760
|
+
|
|
761
|
+
**A tooltip on a popover trigger**
|
|
762
|
+
|
|
763
|
+
- Hovering shows the tooltip, and pressing opens the popover instead.
|
|
764
|
+
- Escape closes the tooltip and leaves the popover open.
|
|
765
|
+
|
|
766
|
+
**Disabled buttons**
|
|
767
|
+
|
|
768
|
+
- Browsers send hover events to a disabled button.
|
|
769
|
+
- An aria-disabled trigger shows its tooltip on hover and focus and ignores presses.
|
|
770
|
+
|
|
771
|
+
**Animation**
|
|
772
|
+
|
|
773
|
+
- The tooltip animates in from its starting style.
|
|
774
|
+
- The tooltip stays in the page while it animates out.
|
|
775
|
+
|
|
776
|
+
**Hidden while closed**
|
|
777
|
+
|
|
778
|
+
- A class that sets display on the content doesn't show it while closed.
|
|
779
|
+
|
|
780
|
+
**Options and dismissal**
|
|
781
|
+
|
|
782
|
+
- Escape closes only a tooltip that keyboard focus opened inside a popover.
|
|
783
|
+
- The pointer can leave the trigger sideways on its way to the tooltip.
|
|
784
|
+
- With closeOnPress false, pressing the trigger keeps the tooltip open.
|
|
785
|
+
- Disabled tooltips never open.
|
|
786
|
+
- A tap on a plain tooltip's trigger only presses it.
|
|
787
|
+
|
|
788
|
+
Runs in React, Vue and web components.
|
|
789
|
+
|
|
790
|
+
Also tested:
|
|
791
|
+
|
|
792
|
+
**Enhancements**
|
|
793
|
+
|
|
794
|
+
- Focus returning to the trigger after its popover closes doesn't reopen the tooltip.
|
|
795
|
+
- Tooltips open at once after another one, without a provider.
|
|
796
|
+
- Focus coming back with the window doesn't reopen the tooltip.
|
|
797
|
+
- A controller opens the tooltip without moving focus.
|
|
798
|
+
- A trigger that's a disabled button warns in development.
|
|
799
|
+
|
|
800
|
+
**Shortcuts**
|
|
801
|
+
|
|
802
|
+
- A trigger connected through a controller shows its tooltip's shortcut in a Shortcut part.
|
|
803
|
+
|
|
804
|
+
**Toggleable**
|
|
805
|
+
|
|
806
|
+
- Pressing a toggleable trigger opens and closes the tooltip.
|
|
807
|
+
- Pressing outside closes a toggleable tooltip.
|
|
808
|
+
- Enter toggles the tooltip from the keyboard and keeps focus on the trigger.
|
|
809
|
+
- A press announces the tooltip's text to screen readers.
|
|
810
|
+
- A tap opens a toggleable tooltip on a touch screen.
|
|
811
|
+
|
|
812
|
+
Runs in React, Vue and web components.
|
|
813
|
+
|
|
814
|
+
Screen readers hear the same thing in each tested framework, recorded by a virtual screen reader:
|
|
815
|
+
|
|
816
|
+
- Announcements while tabbing through triggers with tooltips.
|
|
817
|
+
|
|
818
|
+
Runs in React, Vue and web components.
|