# Tooltip (@limerdev/zest) A short label shown when its trigger is hovered or focused with the keyboard, and announced as the trigger's description. Escape hides it. Put one `Tooltip.Provider` around the app; each tooltip is a `` with a `Tooltip.Trigger` and a `Tooltip.Content`. - Category: Overlays - Import: `import { Tooltip } from '@limerdev/zest'` - Bits UI: `Tooltip`, https://bits-ui.com/docs/components/tooltip - Exports: `Tooltip.Root`, `Tooltip.Provider`, `Tooltip.Trigger`, `Tooltip.Content`, `Tooltip.Portal` - Use for: Naming an icon-only button, or a brief hint about a control. - Don't: Information the user needs and can't get otherwise: touch screens can't hover. Links or buttons inside a tooltip: use `Popover`. A tooltip as an icon button's only name: give the button `aria-label` too. ```svelte Archive ``` Props of `Tooltip.Root`: - `delayDuration` (`number`, default `700`): The delay in milliseconds before the tooltip opens. - `disableCloseOnTriggerClick` (`boolean`, default `false`): When `true`, the tooltip will not close when you click on the trigger. - `disabled` (`boolean`, default `false`): When `true`, the tooltip will be disabled and will not open. - `disableHoverableContent` (`boolean`, default `false`): Prevents tooltip from remaining open when hovering over the content. - `ignoreNonKeyboardFocus` (`boolean`, default `false`): Prevent the tooltip from opening if the focus did not come using the keyboard. - `onOpenChange` (`OnChangeFn`): A callback that will be called when the tooltip is opened or closed. - `onOpenChangeComplete` (`OnChangeFn`): A callback that will be called when the tooltip is opened or closed. - `open` (`boolean`, default `false`, bindable): The open state of the tooltip. - `tether` (`TooltipTether`): Shared tether used to connect detached triggers and infer payload types. - `triggerId` (`string | null`): The active trigger id for controlled single tooltip mode. Props of `Tooltip.Provider`: - `delayDuration` (`number`, default `400`): The delay in milliseconds before the tooltip opens. - `disableCloseOnTriggerClick` (`boolean`, default `false`): When `true`, the tooltip will not close when you click on the trigger. - `disabled` (`boolean`, default `false`): When `true`, the tooltip will be disabled and will not open. - `disableHoverableContent` (`boolean`, default `false`): Prevents tooltip from remaining open when hovering over the content. - `ignoreNonKeyboardFocus` (`boolean`, default `false`): Prevent the tooltip from opening if the focus did not come using the keyboard. - `skipDelayDuration` (`number`, default `300`): How much time a user has to enter another trigger without incurring a delay again. Props of `Tooltip.Trigger`: - `disabled` (`null | false | true`, default `false`): Whether the tooltip trigger is disabled or not. - `payload` (`unknown`): Payload for the trigger used by singleton tooltip root snippets. - `size` (`"default" | "sm" | "lg" | "icon" | "icon-sm" | "icon-lg"`, default `'default'`): The height and padding, from the theme's field size; the `icon` sizes are square. - `tether` (`TooltipTether`): Shared tether used to connect detached triggers and infer payload types. - `variant` (`"link" | "primary" | "secondary" | "neutral" | "error" | "outline" | "ghost"`, default `'primary'`): The look, by the theme's colour roles: `primary` for the main action, `error` for deleting, `secondary`, `neutral` and `outline` for the rest, `ghost` in toolbars, `link` for a navigation that looks like text. Props of `Tooltip.Content`: - `align` (`"start" | "center" | "end"`): The preferred alignment of the anchor to render against when open. This may change when collisions occur. - `alignOffset` (`number`): An offset in pixels from the "start" or "end" alignment options. - `arrowPadding` (`number`): This describes the padding between the arrow and the edges of the floating element. If your floating element has border-radius, this will prevent it from overflowing the corners. - `avoidCollisions` (`boolean`, default `true`): When `true`, overrides the `side` and `align` options to prevent collisions with the boundary edges. - `collisionBoundary` (`Arrayable`): A boundary element or array of elements to check for collisions against. - `collisionPadding` (`number | Partial>`, default `8`): The amount in pixels of virtual padding around the viewport edges to check for overflow which will cause a collision. - `customAnchor` (`string | HTMLElement | Measurable | null`): Use an element other than the trigger to anchor the content to. If provided, the content will be anchored to the provided element instead of the trigger. You can pass a selector string or an HTMLElement. - `dir` (`"ltr" | "rtl"`): The text direction of the content. - `escapeKeydownBehavior` (`"close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore"`, default `close`): Escape behavior type. `close`: Closes the element immediately. `defer-otherwise-close`: Delegates the action to its parent component that has an escape keydown handler. If no parent is found, it closes the element. `defer-otherwise-ignore`: Delegates the action to the parent element. If no parent is found, nothing is done. `ignore`: Prevents the element from closing and also blocks the parent element from closing in response to an escape key press. - `forceMount` (`boolean`): When `true`, the tooltip will be forced to mount in the DOM. Useful for more control over the transition behavior. - `hideWhenDetached` (`boolean`) - `interactOutsideBehavior` (`"close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore"`, default `close`): Interact outside behavior type. `close`: Closes the element immediately. `defer-otherwise-close`: Delegates the action to the parent element. If no parent is found, it closes the element. `defer-otherwise-ignore`: Delegates the action to the parent element. If no parent is found, nothing is done. `ignore`: Prevents the element from closing and also blocks the parent element from closing in response to an outside interaction. - `onEscapeKeydown` (`((e: KeyboardEvent) => void)`): Callback fired when escape is pressed. - `onFocusOutside` (`((event: FocusEvent) => void)`): Callback fired when focus leaves the dismissible layer. - `onInteractOutside` (`InteractOutsideEventHandler`): Callback fired when an outside interaction event completes, which is either a `pointerup`, `mouseup`, or `touchend` event, depending on the user's input device. - `portalProps` (`PortalProps`): Props for the portal the content renders in: `to` (the element to render in, the body by default) and `disabled` (render in place). - `side` (`"top" | "right" | "bottom" | "left"`, default `'top'`): The preferred side of the anchor to render against when open. Will be reversed when collisions occur. - `sideOffset` (`number`, default `6`): The distance in pixels from the anchor to the floating element. - `sticky` (`"partial" | "always"`) - `strategy` (`"absolute" | "fixed"`): The positioning strategy to use for the floating element. - `updatePositionStrategy` (`"always" | "optimized"`, default `"optimized"`): "optimized" will only update the position when necessary, while "always" will update the position on each animation frame, which is useful if the floating content is following something like a mouse cursor. Props of `Tooltip.Portal`: - `disabled` (`boolean`, default `false`): Disable portalling and render the component inline - `to` (`PortalTarget`, default `document.body`): Where to portal the content to. Example: Icon buttons Tooltips name icon-only buttons; each button still has its own aria-label. Put one Tooltip.Provider around the app. ```svelte {#each actions as action (action.label)} {action.label} {/each} ``` Example: Sides side places the tooltip; it flips when there is no room. ```svelte {#each sides as side (side)} {side} Shown on the {side} {/each} ```