Tooltip
Short hint text on hover and keyboard focus.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- Built on native ARIA (shared positioning)
- 3 parts, named exports
- Shows on hover and on keyboard focus; the trigger gets aria-describedby while it is open.
- Escape dismisses it; it stays open while the pointer is over it.
- Never the only place for essential information: touch users do not get hover.
- Styles in one file:
tooltip.css
Import
import '@monoline/css';
import {Tooltip} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add tooltip
Usage
import {Button, Tooltip, TooltipProvider} from '@monoline/react';
<TooltipProvider>
<div style={{display: 'flex', gap: 'var(--s3)'}}>
<Tooltip content="Saved to ~/Notes">
<Button variant="line">Save</Button>
</Tooltip>
<Tooltip content="Below" side="bottom">
<Button variant="line">Bottom</Button>
</Tooltip>
</div>
</TooltipProvider>
Anatomy
Import the parts you need and nest them like this.
import {Tooltip, TooltipProvider, TooltipContent} from '@monoline/react';
<Tooltip>
<TooltipProvider />
<TooltipContent />
</Tooltip>
Examples
Basic
Props
TooltipProps
| Prop | Type | Default | Description |
|---|---|---|---|
content required | ReactNode | – | The text shown. Keep it short; it repeats or extends a label and must never hold essential information alone. |
children required | ReactNode | – | The trigger element. It receives aria-describedby when open. |
side | "top" | "right" | "bottom" | "left" | 'top' | Which side of the trigger the tooltip appears on: `top` (default), `right`, `bottom` or `left`. |
delayDuration | number | 700 | Milliseconds to wait before showing on hover. Defaults to the `TooltipProvider` value. |
open | boolean | – | Whether the tooltip is open when controlled. Pair with `onOpenChange`. |
defaultOpen | boolean | false | Whether the tooltip starts open when uncontrolled. Default false. |
onOpenChange | ((open: boolean) => void) | – | Called with the new open state when the tooltip shows or hides. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
This component sets no state attributes.
CSS classes
| Class | Stylesheet |
|---|---|
.tooltip | tooltip.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.tooltip {
border-color: var(--accent);
}
Try the props
Change a prop and the component above updates; the code below is what you would write. To edit the code itself, use the Playground.
example.tsx
<TooltipProvider>
<Tooltip content="Saved to ~/Notes" defaultOpen>
<Button>Hover or focus me</Button>
</Tooltip>
</TooltipProvider>
Accessibility
- Shows on hover and on keyboard focus; the trigger gets aria-describedby while it is open.
- Escape dismisses it; it stays open while the pointer is over it.
- Never the only place for essential information: touch users do not get hover.
Keyboard
| Keys | Action |
|---|---|
| Escape | Dismisses it |