Tooltip
A short label shown on hover or focus.
Keyboard focus opens a tooltip at once; hovering waits for its delay. A tooltip can’t
hold anything interactive; use a popover for that.
Dependencies
What it's built from and what's built from it in Mocha, read from the imports in its source.
| Uses | Textprimitive |
|---|---|
| Used by | Nothing yet. |
| Packages | @ui-sdk/core@0.1.0-beta.20@ui-sdk/react@0.1.0-beta.20 |
Installation
Set the project up for Mocha once first, as Getting started shows. Then add it with the CLI, or by hand.
With the CLI
Manually
Install its packages:
Add the components it uses first, listed under Dependencies.
Then copy the source:
API reference
Generated from Mocha's types. Props marked ours are added here; the rest come from the ui-sdk part it wraps. Every part also accepts its element's native attributes.
Tooltip
A short label or hint that appears when the pointer rests on its trigger or keyboard focus reaches it.
- closeDelay
Milliseconds before the tooltip closes once the pointer leaves the trigger and the tooltip.
Type number · Default 0
- closeOnPress
Whether pressing the trigger closes the tooltip. Set it to
falseto keep it open, like for a copy button whose tooltip turns into "Copied".Type boolean · Default true
- container
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.
Type Element | DocumentFragment | null
- controller
Opens, closes and inspects the tooltip from anywhere, and connects triggers outside it. Create one with
createTooltipController().Type PopupController<any, TooltipOpenChangeReason, {}, string, TooltipPayloadChangeReason>
- debug
Logs every state change with its reason to the console, in development builds.
Type boolean
- defaultOpen
Whether the tooltip starts open, when uncontrolled.
Type boolean · Default false
- delay
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.
Type number · Default 600
- disabled
Stops the tooltip from opening. The trigger keeps working.
Type boolean · Default false
- onOpenChange
Runs when the tooltip wants to open or close.
details.reasonsays why, anddetails.cancel()stops it.Type (open: boolean, details: ChangeDetails<TooltipOpenChangeReason>) => void
- onOpenChangeComplete
Runs once the tooltip has finished opening or closing, after any animation.
Type (open: boolean) => void
- onPayloadChange
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
onOpenChange, and so does a controller'sopen({ payload })on the open tooltip.details.cancel()keeps the previous payload.Type (payload: unknown, details: ChangeDetails<TooltipPayloadChangeReason>) => void
- open
Whether the tooltip is open. Pass it to control the tooltip.
Type boolean
- shortcut
The keyboard shortcut of what the trigger does, like
"mod+s", as a hint. ATooltipShortcutshows it, and the trigger getsaria-keyshortcuts. It doesn't bind the keys: the trigger's ownshortcut, orregisterShortcut, does.Type string
- toggleable
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.
Type boolean · Default false
- type
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.Type "label" | "description"
TooltipContent
The tooltip's text. Keep it short; it can't hold anything interactive.
- align
How the popup lines up with the anchor along that side.
startandendfollow the reading direction. How the tooltip lines up with the trigger along that side.Type "center" | "start" | "end" · Default "center"
- alignOffset
Shift along the anchor, in pixels. Shift along the trigger, in pixels.
Type number · Default 0
- anchor
Positions the popup against this instead of its trigger: an element, a CSS selector, a point like
{ x, y }, or anything withgetBoundingClientRect(). It's read on every check, so it can move. A controller'sopen({ anchor })wins for that open.Type string | Anchor | null
- arrowPadding
Space to keep between the arrow and the popup's corners, in pixels.
Type number · Default 6
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: TooltipContentState<unknown>) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: TooltipContentState<unknown>) => string)
- collisionPadding
Space to keep from the viewport edges, in pixels.
Type number · Default 8
- container
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.
Type Element | DocumentFragment | null
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<TooltipContentState<unknown>>
- 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.
Type "start" | "end" | "top" | "bottom" | "left" | "right" · Default "top"
- sideOffset
Gap between the anchor and the popup, in pixels. Gap between the trigger and the tooltip, in pixels.
Type number · Default 6
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: TooltipContentState<unknown>) => CSSProperties)
TooltipTrigger
The element the tooltip names or describes, usually a button.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: TooltipTriggerState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: TooltipTriggerState) => string)
- controller
Connects a trigger outside the tooltip, like one per table row, to the tooltip with this controller.
Type PopupController<any, TooltipOpenChangeReason, {}, string, TooltipPayloadChangeReason>
- disabled
Stops presses. The button is natively disabled, so it leaves the tab order and its form doesn't submit through it, unless
focusableWhenDisabledis set.Type boolean · Default false
- payload
Data for the content to render when this trigger opens the tooltip, like the row it belongs to.
Type unknown
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<TooltipTriggerState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: TooltipTriggerState) => CSSProperties)