Feedback
Keyboard Tooltip
A tooltip that opens on hover and on keyboard focus alike. The second half is usually forgotten, which leaves the hint unavailable to half the users.
- tooltip
- hint
- accessibility
- no-js
Preview
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/tooltip-001?lang=en
Show the full instructions
What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.
# Install and place "tooltip-001" (Keyboard Tooltip) from VibeUI
## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/tooltip-001.json
Registry item: https://vibeui.ru/r/tooltip-001.json
Installs to: components/vibeui/tooltip-001.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.
Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.
## 2. What it is
A tooltip that opens on hover and on keyboard focus alike. The second half is usually forgotten, which leaves the hint unavailable to half the users.
A tooltip wrapped around any trigger: it opens on hover and on keyboard focus, sits above or below, and draws its tail in CSS. It rests on :hover and :focus-within, so there is no client JS at all. The bubble is role="tooltip" and links to the trigger through aria-describedby. Zero dependencies, one file, its own palette.
## 3. How to use it
import { Tooltip001 } from "@/components/vibeui/tooltip-001"
<Tooltip001 id="copy-tip" tip="Copy the project link">
<button type="button" aria-describedby="copy-tip">Copy</button>
</Tooltip001>
Read the installed file for the full prop list.
## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.
Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)
## 5. Keep exactly as installed
- the local --vibeui-tooltip-001-* palette — do not swap it for your theme tokens (bg-popover, text-popover-foreground and the like)
- treating :hover and :focus-within as equals — a tooltip that does not open from the keyboard is unavailable
- pointer-events:none on the bubble: otherwise it steals the cursor from the trigger
- role="tooltip" and the id the trigger points at through aria-describedby
- the tail as a rotated square with background:inherit — it takes the bubble's colour and never drifts from it
- the transform-based offset rather than moving the position: that is what keeps the entrance from jumping
- the <style> block inside the component — it holds the palette, the sides and the tail
## 6. You may change
- tip — the hint text: one short phrase
- children — your trigger: a button, an icon, a word in a sentence
- side: top or bottom, depending on where there is room
- open — force the bubble visible: onboarding, debugging, a showcase; leave it false in a normal interface
- id — one per tooltip when a page has several
- outer spacing through className
## 7. Rules
- Do not hide anything essential in a tooltip: it never appears on a phone, where there is no hover.
- Do not put links or buttons inside: the pointer cannot reach them, the bubble disappears on the way.
- The trigger has to be focusable — a button or a link. On a <span> the tooltip will not open from the keyboard.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.
## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.For developers
npx shadcn@latest add https://vibeui.ru/r/tooltip-001.jsonhttps://vibeui.ru/r/tooltip-001.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-tooltip-001-*. Появление держат :hover и :focus-within у обёртки, поэтому JS не нужен и компонент остаётся серверным. Хвостик — повёрнутый квадрат того же цвета. Подсказка помечена role="tooltip" и имеет id: свяжите с ним триггер через aria-describedby. Без переданного children рисуется кнопка-заглушка — она нужна только для превью.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
import type { ComponentPropsWithoutRef, CSSProperties, ReactNode } from "react"
export type Tooltip001Props = Omit<
ComponentPropsWithoutRef<"span">,
"children" | "id"
> & {
/** Текст подсказки. */
tip?: string
/** Элемент, к которому она относится: кнопка, иконка, слово в тексте. */
children?: ReactNode
side?: "top" | "bottom"
/** Показать подсказку принудительно: онбординг, отладка, витрина. */
open?: boolean
/** Идентификатор для aria-describedby у вашего триггера. */
id?: string
}
// Идея компонента: подсказка появляется и по наведению, и по фокусу с
// клавиатуры — второе обычно забывают, и подсказка остаётся недоступной
// половине пользователей. Всё держится на :hover и :focus-within, JS не нужен.
const STYLES = `
:where([data-vibeui-block="tooltip-001"]){
--vibeui-tooltip-001-fg:oklch(0.97 0.002 265);
--vibeui-tooltip-001-bg:oklch(0.26 0.014 265);
--vibeui-tooltip-001-radius:0.4375rem;
--vibeui-tooltip-001-gap:0.5rem;
--vibeui-tooltip-001-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="tooltip-001"]{
position:relative;display:inline-flex;font-family:var(--vibeui-tooltip-001-font);
}
[data-vibeui-block="tooltip-001"] [data-part="tip"]{
position:absolute;left:50%;z-index:20;
max-width:16rem;width:max-content;
padding:0.375rem 0.5625rem;
border-radius:var(--vibeui-tooltip-001-radius);
background:var(--vibeui-tooltip-001-bg);color:var(--vibeui-tooltip-001-fg);
font-size:0.75rem;line-height:1.4;text-align:center;
pointer-events:none;opacity:0;
transform:translate(-50%,0.25rem);
transition:opacity .14s ease,transform .14s ease;
}
[data-vibeui-block="tooltip-001"][data-side="top"] [data-part="tip"]{bottom:calc(100% + var(--vibeui-tooltip-001-gap))}
[data-vibeui-block="tooltip-001"][data-side="bottom"] [data-part="tip"]{top:calc(100% + var(--vibeui-tooltip-001-gap));transform:translate(-50%,-0.25rem)}
/* Хвостик — повёрнутый квадрат того же цвета. */
[data-vibeui-block="tooltip-001"] [data-part="tip"]::after{
content:"";position:absolute;left:50%;width:0.5rem;height:0.5rem;
margin-left:-0.25rem;background:inherit;transform:rotate(45deg);
}
[data-vibeui-block="tooltip-001"][data-side="top"] [data-part="tip"]::after{bottom:-0.1875rem}
[data-vibeui-block="tooltip-001"][data-side="bottom"] [data-part="tip"]::after{top:-0.1875rem}
/* Наведение и фокус равноправны: подсказка обязана открываться с клавиатуры. */
[data-vibeui-block="tooltip-001"][data-open="true"] [data-part="tip"],
[data-vibeui-block="tooltip-001"]:hover [data-part="tip"],
[data-vibeui-block="tooltip-001"]:focus-within [data-part="tip"]{
opacity:1;transform:translate(-50%,0);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="tooltip-001"] *{animation:none!important;transition:none!important}}
`
/** Кнопка-заглушка превью: подсказке нужен триггер, а зависимостей у нас нет. */
const DEFAULT_TRIGGER_STYLE = `
[data-vibeui-block="tooltip-001"] [data-part="sample"]{
appearance:none;cursor:pointer;
display:inline-flex;align-items:center;justify-content:center;
width:2.25rem;height:2.25rem;border-radius:0.5rem;
border:1px solid oklch(0.88 0.008 265);background:oklch(1 0 0);
color:oklch(0.35 0.014 265);font:inherit;font-size:0.9375rem;
}
[data-vibeui-block="tooltip-001"] [data-part="sample"]:focus-visible{outline:2px solid oklch(0.55 0.2 262);outline-offset:2px}
`
/**
* Подсказка, открывающаяся и по наведению, и по фокусу с клавиатуры.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Tooltip001({
tip = "Скопировать ссылку на проект",
children,
side = "top",
open = false,
id = "vibeui-tooltip-001",
className,
style,
...props
}: Tooltip001Props) {
return (
<>
<style href="vibeui-tooltip-001" precedence="medium">
{STYLES + DEFAULT_TRIGGER_STYLE}
</style>
<span
{...props}
data-vibeui-block="tooltip-001"
data-side={side}
data-open={open || undefined}
className={className}
style={style as CSSProperties}
>
{children ?? (
<button data-part="sample" type="button" aria-describedby={id}>
⧉
</button>
)}
<span data-part="tip" role="tooltip" id={id}>
{tip}
</span>
</span>
</>
)
}