v0.0.2
Demos (demo panel, opens in a new tab)

Tooltip

A short, single-line explanation that appears on mouse hover or keyboard focus.

zb:tooltip zubazar/ui · free (MIT)

Basic usage

Basic usage: view
BLADE

Put the element to describe inside the component and give the text with text.

blade
<div class="py-6">
    <zb:tooltip text="The customer's order history">
        <zb:button variant="white" size="sm">History</zb:button>
    </zb:tooltip>
</div>
PropValues
textTooltip text (single line)

Position

Position: view
BLADE

The tooltip opens above the element; near the top edge of the page, use position="bottom".

blade
<div class="flex gap-4 py-6">
    <zb:tooltip text="Opens above"><zb:button variant="outline-dark" size="sm">Top</zb:button></zb:tooltip>
    <zb:tooltip text="Opens below" position="bottom"><zb:button variant="outline-dark" size="sm">Bottom</zb:button></zb:tooltip>
</div>
PropValues
positiontop | bottom

Icon buttons

Icon buttons: view
BLADE

Use tooltips on icon-only buttons, and still give the button an aria-label.

blade
<div class="flex gap-1 py-6">
    <zb:tooltip text="Edit">
        <zb:button variant="ghost" size="icon" aria-label="Edit"><zb:icon name="pencil-square" /></zb:button>
    </zb:tooltip>
    <zb:tooltip text="Print">
        <zb:button variant="ghost" size="icon" aria-label="Print"><zb:icon name="printer" /></zb:button>
    </zb:tooltip>
    <zb:tooltip text="Delete permanently">
        <zb:button variant="ghost" size="icon" aria-label="Delete permanently" class="text-danger-ink"><zb:icon name="trash" /></zb:button>
    </zb:tooltip>
</div>
PropValues
aria-labelAccessible name of the button
aria-describedbyAutomatic: added to the first focusable element in the slot

In scrollable areas

In scrollable areas: view
BLADE

The tooltip is not cut off at the edge of scrolling areas; add tabindex="0" to an element that cannot take focus, such as a badge.

blade
<div class="max-w-xs overflow-x-auto rounded-sm border border-line py-6">
    <div class="flex w-[36rem] items-center gap-6 px-4 text-sm">
        <span>Kadıköy warehouse</span>
        <zb:tooltip text="Warehouse code: KDK-01"><zb:badge variant="info" tabindex="0">KDK-01</zb:badge></zb:tooltip>
        <span>312 orders</span>
    </div>
</div>

Props

The values the component takes. What are props and slots?

PropTypeDefaultDescription
text—''Tooltip text (role="tooltip")
position—toptop · bottom

Slots: default: the element the tooltip is attached to; the first focusable element inside it (a link, a button, a form field or an element with tabindex) gets aria-describedby. Hover and focus open it, Esc closes it.

Developer notes

Events, hooks and details
  • For explanations longer than a few words, use a popover (zb:popover).
  • The tooltip is rendered at the outermost level of the page (body), so horizontally scrolling tables and panels do not cut it off.

Accessibility

ARIA and roles
The tooltip has role="tooltip". The first link, button or form field inside is linked to it with aria-describedby, so screen readers read the text as that element description.
Showing and hiding
It opens on hover and on keyboard focus, and closes when focus leaves. The pointer can move onto the tooltip; a short delay keeps it open.
Keyboard
Escape hides it, even when the pointer opened it. While focus is on the element, Escape closes only the tooltip, not a modal or drawer around it.
What you provide
The content must be focusable: give plain text or an icon tabindex="0". A tooltip is a description, not a name, so an icon-only button still needs an aria-label.
Zubazar UI · ZubazarDesigned for people.