DocumentationTooltips
Tooltips
A little context, exactly where it belongs.
Getting started
Install the package
Use React 19 and import the package stylesheet once in your app’s global CSS. The bundled styles are built for Tailwind CSS 4.
bun add @rentnerkev/tooltips@import '@rentnerkev/tooltips/tailwind.css';Tooltips 2.3.2: long content & zoom#
Default content styling wraps unbroken tokens. With collision avoidance enabled, the content body is clipped to the available height after accounting for padding and borders; the arrow remains outside that clipped body. The complete text stays available through the trigger description. The tooltip does not gain a tab stop or a scroll control. Offer long or essential information in a visible, keyboard-accessible panel as well.
import { CustomTooltip } from '@rentnerkev/tooltips'
const identifier = 'package_identifier_'.repeat(40)
export default function LongIdentifier() {
return (
<>
<CustomTooltip collisionPadding={12} content={identifier}>
<button type="button">Inspect identifier</button>
</CustomTooltip>
<details>
<summary>Full identifier</summary>
<p className="[overflow-wrap:anywhere]">{identifier}</p>
</details>
</>
)
}Tooltips 2.3: native implementation#
Version 2.3.0 replaces Radix Tooltip with an implementation using React and DOM APIs. Keep the existing CustomTooltip and TooltipProvider imports, props and design slots. Use a focusable trigger that forwards props and its ref; hover and keyboard focus open the hint. Placement, collision handling, portal defaults and shared provider timing remain configurable through the existing API.
import { CustomTooltip } from '@rentnerkev/tooltips'
export default function NativeTooltip() {
return (
<CustomTooltip content="Save your changes">
<button type="button">Save</button>
</CustomTooltip>
)
}Provider positioning & design slots#
New in 2.2.0: TooltipProvider shares placement, collision and portal defaults as well as size and showArrow. Nested providers and local props override only defined values, including false, zero, empty classes and a null portal container. The outermost provider owns shared hover timing. size accepts sm, md or lg; md uses 14 px text and lg 16 px. classNames replaces the content, animation, arrow and disabledTrigger visual slots. portalClassName styles the visible content; portalZIndex overrides --rentner-tooltip-z (9999).
import { CustomTooltip, TooltipProvider } from '@rentnerkev/tooltips'
import type { TooltipClassNames } from '@rentnerkev/tooltips'
const slots: TooltipClassNames = {
content:
'rounded-lg border border-sky-700 bg-white px-3 py-2 text-slate-900',
disabledTrigger: 'inline-flex',
}
export default function Toolbar() {
return (
<TooltipProvider
classNames={slots}
collisionPadding={16}
portalClassName="font-sans"
portalZIndex={12000}
side="right"
sideOffset={10}
size="md"
>
<CustomTooltip content="Create a package">
<button type="button">Create</button>
</CustomTooltip>
<CustomTooltip
content="Choose a package first"
disabledTrigger
showArrow={false}
side="bottom"
>
<button disabled type="button">
Send
</button>
</CustomTooltip>
</TooltipProvider>
)
}Local AI helpers: metadata & guides#
Import the /ai entry in a local Node.js or Bun script. These synchronous, read-only helpers use node:fs to read the installed package without importing its UI. getPackageInfo() returns PackageInfo, including the installed version, public exports and peer dependencies. getPackageDocumentation() returns a PackageDocument with path and content; its default is usage, and readme selects README.md. Only these two packaged documents are accepted. Results describe your installed version, which can differ from this website.
import { getPackageDocumentation, getPackageInfo } from '@rentnerkev/tooltips/ai'
import type { PackageDocument, PackageInfo } from '@rentnerkev/tooltips/ai'
const info: PackageInfo = getPackageInfo()
const usage: PackageDocument = getPackageDocumentation()
const readme = getPackageDocumentation('readme')
console.log(info.name, info.version, info.exports, info.peerDependencies)
console.log(usage.path, usage.content)
console.log(readme.path, readme.content)Local AI helpers: public declarations#
getPackageApi() returns PackageApi with package, installed version, selected subpaths and declarations as PackageDocument objects. It reads public typed entries and their local declaration dependencies; /ai itself is excluded. Use subpath such as . or ./types to select a public entry. symbol validates that a name is exported by the selected entry; it does not trim declaration files to that symbol. Unknown subpaths, invalid names and names not exported by the selected entry throw errors. Callers cannot provide arbitrary file paths.
import { getPackageApi } from '@rentnerkev/tooltips/ai'
import type { PackageApi } from '@rentnerkev/tooltips/ai'
const api: PackageApi = getPackageApi()
const selected = getPackageApi({ subpath: '.', symbol: 'CustomTooltip' })
console.log(api.package, api.version, api.subpaths)
for (const declaration of selected.declarations) {
console.log(declaration.path, declaration.content)
}Local AI helpers: search & examples#
searchPackageDocumentation(query) searches README.md and docs/usage.md using a trimmed, case-insensitive literal query. It returns PackageSearchMatch objects with path, a one-based line number and matching text; an empty query returns an empty array. getPackageExamples() returns every fenced code block from the installed usage guide as a PackageExample with language and code. These helpers return text for your own tools; they do not execute examples or contact an AI service.
import { getPackageExamples, searchPackageDocumentation } from '@rentnerkev/tooltips/ai'
import type { PackageExample, PackageSearchMatch } from '@rentnerkev/tooltips/ai'
const matches: PackageSearchMatch[] = searchPackageDocumentation('CustomTooltip')
const examples: PackageExample[] = getPackageExamples()
for (const match of matches) {
console.log(match.path, match.line, match.text)
}
for (const example of examples) {
console.log(example.language, example.code)
}CustomTooltip#
Wrap one React element in CustomTooltip and pass text or JSX as content. The child is the actual trigger, so use a focusable button or link and forward its props and ref when wrapping your own component. Hover or keyboard focus opens the hint. A provider is created automatically when no TooltipProvider is present.
import { CustomTooltip } from '@rentnerkev/tooltips'
export default function SaveButton() {
return (
<CustomTooltip content="Save your changes">
<button type="button">Save</button>
</CustomTooltip>
)
}TooltipProvider & timing#
Share hover timing across a group of controls. delayDuration sets the initial wait in milliseconds; skipDelayDuration sets the window in which the next tooltip opens without waiting. A tooltip can override delayDuration locally. disableHoverableContent closes the tooltip as the pointer leaves the trigger instead of allowing it to move into the content.
import { CustomTooltip, TooltipProvider } from '@rentnerkev/tooltips'
export default function Toolbar() {
return (
<TooltipProvider delayDuration={300} skipDelayDuration={500}>
<CustomTooltip content="Create a package">
<button type="button">Create</button>
</CustomTooltip>
<CustomTooltip content="Send immediately" delayDuration={0}>
<button type="button">Send</button>
</CustomTooltip>
</TooltipProvider>
)
}Placement & collision handling#
side chooses top, right, bottom or left; align chooses start, center or end. sideOffset and alignOffset add pixel spacing. avoidCollisions, collisionBoundary and collisionPadding keep the content inside available space. arrowPadding protects the arrow near corners; sticky controls partial or always-on sticking, and hideWhenDetached hides content when its trigger leaves the boundary. portalContainer targets a specific DOM container; the default portal renders outside the trigger layout.
import { CustomTooltip } from '@rentnerkev/tooltips'
export default function Placement() {
return (
<CustomTooltip
align="start"
alignOffset={4}
arrowPadding={8}
avoidCollisions
collisionPadding={16}
content="This hint stays within the viewport"
hideWhenDetached
side="right"
sideOffset={12}
sticky="partial"
>
<button type="button">Inspect</button>
</CustomTooltip>
)
}Controlled & initial open state#
Use open and onOpenChange together to control visibility with React state. Use defaultOpen for an initially open, uncontrolled tooltip. disabled bypasses the tooltip entirely and returns the child. Keep essential instructions visible outside a tooltip, because touch users and assistive technology must still be able to complete the action.
import { useState } from 'react'
import { CustomTooltip } from '@rentnerkev/tooltips'
export default function ControlledHint() {
const [open, setOpen] = useState(false)
return (
<CustomTooltip
content="Ready to ship"
onOpenChange={setOpen}
open={open}
>
<button type="button">Shipment</button>
</CustomTooltip>
)
}Hints on disabled controls#
A disabled button does not receive normal focus or pointer events. Set disabledTrigger to add the package’s focusable wrapper and explain why the action is unavailable. disabledTriggerClassName styles that wrapper. This differs from disabled, which removes the tooltip itself.
import { CustomTooltip } from '@rentnerkev/tooltips'
export default function UnavailableAction() {
return (
<CustomTooltip
content="Choose a package before sending"
disabledTrigger
disabledTriggerClassName="inline-flex"
>
<button disabled type="button">
Send
</button>
</CustomTooltip>
)
}Custom design & defaultTooltipDesign#
customDesign overrides four class slots: baseClasses for the shell, animationClasses for transitions, contentClasses for spacing and typography, and arrowClasses for the arrow. Unspecified slots retain defaultTooltipDesign. Import the Tailwind stylesheet once and make sure Tailwind scans the files containing your own class names.
import { CustomTooltip, defaultTooltipDesign } from '@rentnerkev/tooltips'
import type { TooltipCustomDesign } from '@rentnerkev/tooltips/types'
const design: TooltipCustomDesign = {
...defaultTooltipDesign,
baseClasses: 'border-2 border-amber-600 bg-amber-100 text-stone-900',
contentClasses: 'px-3 py-2 text-sm',
arrowClasses: 'fill-amber-600',
}
export default function StyledHint() {
return (
<CustomTooltip content="Packed with care" customDesign={design}>
<button type="button">Package</button>
</CustomTooltip>
)
}Docs for your AI tools
Connect a compatible MCP client to read package APIs, guides and examples. Public access, no account or API key required.
Remote access is optional: add this public URL yourself to your MCP client. Clients use Streamable HTTP; the configuration format may vary. The local package /ai helpers read the installed version in Node.js or Bun and never connect to this server automatically.
{
"mcpServers": {
"rentnerPackages": {
"url": "https://packages.rentner.dev/mcp"
}
}
}Tools: list_packages, read_package_docs, read_package_api, read_package_examples and search_package_docs.
TypeScript / v2.3.2
API & types
Published signatures, props and types for this version. Expand an entry to inspect its definition and available import paths.
CustomTooltipfunction
@rentnerkev/tooltips@rentnerkev/tooltips/tooltip
export function CustomTooltip(props: TooltipProps): import("react").JSX.ElementTooltipProviderfunction
@rentnerkev/tooltips@rentnerkev/tooltips/tooltip
export function TooltipProvider({ children, disableHoverableContent, ...props }: TooltipProviderProps): import("react").JSX.ElementdefaultTooltipDesignconst
@rentnerkev/tooltips@rentnerkev/tooltips/types
export const defaultTooltipDesign: Required<TooltipCustomDesign>TooltipCustomDesigninterface
@rentnerkev/tooltips@rentnerkev/tooltips/tooltip@rentnerkev/tooltips/types
export interface TooltipCustomDesign {
baseClasses?: string
animationClasses?: string
contentClasses?: string
arrowClasses?: string
}TooltipClassNamesinterface
@rentnerkev/tooltips@rentnerkev/tooltips/types
export interface TooltipClassNames {
content?: string
animation?: string
arrow?: string
disabledTrigger?: string
}TooltipDefaultsinterface
@rentnerkev/tooltips@rentnerkev/tooltips/types
export interface TooltipDefaults {
side?: 'top' | 'right' | 'bottom' | 'left'
sideOffset?: number
align?: 'start' | 'center' | 'end'
alignOffset?: number
avoidCollisions?: boolean
collisionBoundary?: Element | null | (Element | null)[]
collisionPadding?: number | Partial<Record<'top' | 'right' | 'bottom' | 'left', number>>
arrowPadding?: number
sticky?: 'partial' | 'always'
hideWhenDetached?: boolean
portalContainer?: Element | DocumentFragment | null
portalClassName?: string
portalZIndex?: number
size?: 'sm' | 'md' | 'lg'
showArrow?: boolean
}TooltipPropsinterface
@rentnerkev/tooltips@rentnerkev/tooltips/tooltip@rentnerkev/tooltips/types
export interface TooltipProps extends TooltipDefaults {
children: ReactElement
content: ReactNode
disabled?: boolean
disabledTrigger?: boolean
disabledTriggerClassName?: string
open?: boolean
defaultOpen?: boolean
onOpenChange?: (open: boolean) => void
delayDuration?: number
disableHoverableContent?: boolean
customDesign?: TooltipCustomDesign
classNames?: TooltipClassNames
}TooltipProviderPropsinterface
@rentnerkev/tooltips@rentnerkev/tooltips/tooltip@rentnerkev/tooltips/types
export interface TooltipProviderProps extends TooltipDefaults {
children: ReactNode
customDesign?: TooltipCustomDesign
classNames?: TooltipClassNames
delayDuration?: number
skipDelayDuration?: number
disableHoverableContent?: boolean
}PackageInfointerface
@rentnerkev/tooltips/ai
export interface PackageInfo {
name: string
version: string
description: string
license: string
homepage: string
repository: {
type: string
url: string
}
exports: Record<string, string | {
types?: string
import?: string
default?: string
}>
peerDependencies: Record<string, string>
}PackageDocumentinterface
@rentnerkev/tooltips/ai
export interface PackageDocument {
path: string
content: string
}PackageApiinterface
@rentnerkev/tooltips/ai
export interface PackageApi {
package: string
version: string
subpaths: Record<string, string>
declarations: PackageDocument[]
}PackageSearchMatchinterface
@rentnerkev/tooltips/ai
export interface PackageSearchMatch {
path: string
line: number
text: string
}PackageExampleinterface
@rentnerkev/tooltips/ai
export interface PackageExample {
language: string
code: string
}getPackageInfofunction
@rentnerkev/tooltips/ai
export function getPackageInfo(): PackageInfogetPackageDocumentationfunction
@rentnerkev/tooltips/ai
export function getPackageDocumentation(document?: 'readme' | 'usage'): PackageDocumentgetPackageApifunction
@rentnerkev/tooltips/ai
export function getPackageApi(options?: {
subpath?: string
symbol?: string
}): PackageApisearchPackageDocumentationfunction
@rentnerkev/tooltips/ai
export function searchPackageDocumentation(query: string): PackageSearchMatch[]getPackageExamplesfunction
@rentnerkev/tooltips/ai
export function getPackageExamples(): PackageExample[]