Fragiola

API: components

Tooltip

A control's short description, shown on hover and keyboard focus, wired as its accessible description, following the APG tooltip pattern in each framework.

A short description of a control, shown while the control is hovered or keyboard-focused. It never takes focus and holds nothing interactive. The primitive wires it itself: the popup is a tooltip and the trigger's aria-describedby points at it, so what it says is the control's accessible description (the control still needs its own name). It follows the WAI-ARIA APG tooltip pattern, and stays open while hovered (WCAG 1.4.13).

Toolbar hints
Gallery

Behaviour

  • Hover: the pointer entering the Trigger opens it after delay (reason trigger-hover); leaving before then cancels. A touch tap never opens it.
  • Hoverable: leaving the Trigger closes it after closeDelay, unless the pointer moves onto the popup (across the gap): it stays open while hovered, and closes when the pointer leaves both, or leaves the window (or the iframe the page is in) at once.
  • Keyboard: keyboard focus on the Trigger opens it at once (trigger-focus, data-instant); blur closes it. Escape closes it (escape-key), keeps focus on the trigger, and stops there: an enclosing dialog stays open.
  • Press: a press on the Trigger closes it (trigger-press); it does not reopen until the pointer leaves and comes back.
  • Delay group: within one Provider, one tooltip is open at a time. Moving from an open tooltip's trigger to another one opens it at once (data-instant), also within timeout ms of the last close.
  • Positioning: as the Popover's, from the Trigger, on the top by default.
  • Detached triggers: Triggers anywhere in the page show the same Root through a handle, each with a payload the content reads (detached triggers). Hovering another trigger of the open tooltip moves it there at once.
  • Lifecycle: onOpenChange is called before the change (details.cancel() keeps it as it is, change details), onOpenChangeComplete(open) reports the end of each transition, the actions close() and unmount() act from code, and the Portal's keepMounted keeps the Positioner in the page while closed (hidden, data-closed).

Anatomy

partelementdata-primitives-partrole
Providernonea delay group: shared delays and the instant hand-off
Rootnoneholds the state
Triggerbuttontooltip-triggerthe described control, and the anchor
Portalnonemoves the Positioner to the end of body
Positionerdivtooltip-positionerplaces the popup next to the trigger
Popupdivtooltip-popupthe tooltip
Arrowdivtooltip-arrowpoints at the trigger (optional)

Usage

import { Tooltip } from "@fragiola/primitives-react/tooltip";

<Tooltip.Provider delay={500}>
    <Tooltip.Root>
        <Tooltip.Trigger>Bold</Tooltip.Trigger>
        <Tooltip.Portal>
            <Tooltip.Positioner sideOffset={8}>
                <Tooltip.Popup>
                    <Tooltip.Arrow />
                    Bold (Ctrl+B)
                </Tooltip.Popup>
            </Tooltip.Positioner>
        </Tooltip.Portal>
    </Tooltip.Root>
</Tooltip.Provider>;

Props

Every part also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards. The names below are React's; Vue binds them the same way (v-model:open, @open-change), and Angular as inputs and outputs ([(open)], (openChangeDetails)).

Provider

proptypedefaultdescription
delaynumber600ms before a hovered trigger opens its tooltip
closeDelaynumber0ms before a tooltip closes once the pointer left
timeoutnumber400ms after a close during which another tooltip of the group opens at once

Root

proptypedefaultdescription
openbooleanthe open state, controlled
defaultOpenbooleanfalsethe initial open state, uncontrolled
onOpenChange(open: boolean, details: OpenChangeDetails) => voidevery change, with its reason (trigger-hover, trigger-focus, trigger-press, escape-key); called before the change, details.cancel() stops it
onOpenChangeComplete(open: boolean) => voidonce an opening or a closing has finished its transitions (not on the first render, nor for an exit a reopening interrupted)
actionsRef (react){ current: OverlayActions | null }receives close() (reason imperative-action) and unmount() (ends an exit now); Vue exposes them on the Root's template ref, Angular as the root directive's methods
handleTooltipHandle<Payload>connects Triggers rendered outside the Root (detached triggers)
triggerIdstring | nullthe active trigger's id, controlled together with open
defaultTriggerIdstring | nullnullthe initial active trigger, uncontrolled
delaynumberthe Provider's, else 600ms before a hovered trigger opens it
closeDelaynumberthe Provider's, else 0ms before it closes once the pointer left
disabledbooleanfalsea disabled tooltip never opens

Trigger

proptypedefaultdescription
handleTooltipHandle<Payload>the handle of a Root this Trigger opens from anywhere, outside it
payloadPayloadwhat the Root's content receives while this Trigger is the active one
idstringgeneratedthe Trigger's id: triggerId and the handle's open(id) name it

Portal

proptypedefaultdescription
container (react, vue)Elementdocument.bodywhere the Positioner goes
keepMounted (react, vue)booleanfalsekeep the content rendered while closed (before the first opening and after an exit), hidden and data-closed; reopening shows the same elements
options (angular)Element | { container?, keepMounted? }{}the same two options: *tooltipPortal="{ keepMounted: true }", or *tooltipPortal="element" for a container alone

Positioner

proptypedefaultdescription
side"top" | "bottom" | "inline-start" | "inline-end" | "left" | "right""top"the side of the trigger; inline-* follow the direction
align"start" | "center" | "end""center"the alignment along that side
sideOffsetnumber0the distance from the trigger, in px
alignOffsetnumber0the shift along the trigger's edge, in px
collisionPaddingnumber8the space kept from the viewport's edges, in px
anchorElementthe triggerthe element to place the popup next to

No props of its own.

Arrow

No props of its own.

State and part attributes

partattributes
Triggeraria-describedby (the popup while open, added to the consumer's own), data-popup-open
Positionerrole="presentation", data-side, data-align, data-open / data-closed; the anchor CSS variables, as the Popover's; hidden while kept mounted and closed
Popuprole="tooltip", an id, data-side, data-align, data-open / data-closed, data-instant (opened with no delay), data-starting-style, data-ending-style
Arrowaria-hidden="true", data-side, data-align

Keyboard

keyaction
Tab onto the Triggeropens at once
Tab awaycloses
Escapecloses, focus stays on the trigger

Exports

entryexports
@fragiola/primitives-react/tooltipTooltip, TooltipProviderProps, TooltipRootProps, TooltipPortalProps, TooltipPositionerProps, TooltipPositionerState, TooltipPopupState, PositionerProps, Side, Align, ChangeDetails, ChangeReason, RenderProp, OpenChangeDetails, OverlayActions, OverlayHandle, OverlayPortalProps, OverlayRootProps, OverlayTriggerProps, OverlayTriggerRootProps, TooltipHandle, TooltipTriggerProps, createTooltipHandle
@fragiola/primitives-vue/tooltipTooltip, TooltipProviderProps, TooltipRootProps, TooltipRootEmits, TooltipTriggerState, TooltipPortalProps, TooltipPositionerState, TooltipPopupState, TooltipArrowState, PositionerProps, Side, Align, ChangeDetails, ChangeReason, RenderSlotProps, OpenChangeDetails, OverlayActions, OverlayHandle, OverlayPortalProps, OverlayRootEmits, OverlayRootProps, OverlayRootSlots, OverlayTriggerProps, OverlayTriggerRootProps, TooltipHandle, TooltipTriggerProps, createTooltipHandle
@fragiola/primitives-angular/tooltipTooltipProvider, TooltipRoot, TooltipTrigger, TooltipPortal, TooltipPositioner, TooltipPopup, TooltipArrow, injectTooltip, TooltipState, TooltipPopupState, Side, Align, ChangeDetails, ChangeReason, OpenChangeEvent, OpenChangeDetails, OverlayActions, OverlayHandle, OverlayPortalOptions, TooltipHandle, TooltipTriggerState, createTooltipHandle