Skip to content
GitHub11 stars

A popup that appears when an element is hovered or focused, showing a hint for sighted users.

<TooltipProvider>
    <div class="tooltip-panel">
        <TooltipRoot>

Usage guidelines

  • Prefer using tooltips as visual labels only: Tooltips are supplementary visual labels for sighted mouse and keyboard users. On their own they aren't accessible to touch or screen reader users.
  • Provide an accessible name for the trigger: A tooltip doesn't label its trigger. Give the trigger an aria-label that closely matches the tooltip's content, so screen reader users get the same information.

Anatomy

Import the primitives and assemble the parts:

@using Blazix.Primitives

<TooltipProvider>
    <TooltipRoot>
        <TooltipTrigger />
        <TooltipPortal>
            <TooltipPositioner>
                <TooltipPopup>
                    <TooltipArrow />
                    <TooltipViewport />
                </TooltipPopup>
            </TooltipPositioner>
        </TooltipPortal>
    </TooltipRoot>
</TooltipProvider>

API Reference

TooltipRoot

Doesn't render its own HTML element.

ParameterTypeDefault
Disabled

Whether the component should ignore user interaction.

bool false
HoverablePopup bool true
Open bool false
OpenChanged

Called with the new value when Open changes, for @bind-Open.

EventCallback<bool> -
OnOpenChange EventCallback<OpenChangeEventArgs> -
OnOpenChangeComplete EventCallback<bool> -
Handle PopupHandle? -
ContentTemplate RenderFragment<object?>? -
ChildContent

The part's content.

RenderFragment? -

TooltipProvider

Doesn't render its own HTML element.

ParameterTypeDefault
Delay int? -
CloseDelay int? -
Timeout int 400
ChildContent

The part's content.

RenderFragment? -

TooltipTrigger

Renders a <button> element.

ParameterTypeDefault
Delay int? -
CloseDelay int? -
Disabled

Whether the component should ignore user interaction.

bool false
Handle PopupHandle? -
Payload object? -
NativeButton bool? -
Render RenderFragment<PopupTriggerRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-popup-open

Present when the corresponding tooltip is open.

-
data-trigger-disabled

Present when the trigger is disabled, either by the disabled prop or by a parent <TooltipRoot> component.

-

TooltipPortal

Doesn't render its own HTML element.

ParameterTypeDefault
KeepMounted bool false
ChildContent

The part's content.

RenderFragment? -

TooltipPositioner

Doesn't render its own HTML element.

ParameterTypeDefault
Side Side? -
Align Align? -
SideOffset int? -
AlignOffset int? -
CollisionPadding int? -
ArrowPadding int? -
Sticky bool? -
Anchor string? -
ChildContent

The part's content.

RenderFragment? -
AttributeType
data-open

Present when the tooltip is open.

-
data-closed

Present when the tooltip is closed.

-
data-anchor-hidden

Present when the anchor is hidden.

-
data-align

Indicates how the popup is aligned relative to specified side.

'start' | 'center' | 'end'
data-side

Indicates which side the popup is positioned relative to the trigger.

'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'
CSS variableType
--anchor-height

The anchor's height.

number
--anchor-width

The anchor's width.

number
--available-height

The available height between the trigger and the edge of the viewport.

number
--available-width

The available width between the trigger and the edge of the viewport.

number
--positioner-height

The height of the tooltip's positioner. It is important to set height to this value when using CSS to animate size changes.

number
--positioner-width

The width of the tooltip's positioner. It is important to set width to this value when using CSS to animate size changes.

number
--transform-origin

The coordinates that this element is anchored to. Used for animations and transitions.

string

TooltipPopup

Renders a <div> element.

ParameterTypeDefault
Side Side? -
Align Align? -
SideOffset int? -
AlignOffset int? -
CollisionPadding int? -
ArrowPadding int 5
Sticky bool false
Anchor string? -
FallbackAxis bool? -
KeepMounted bool false
InitialFocus string? -
FinalFocus string? -
PositionerAttributes IReadOnlyDictionary<string, object>? -
Render RenderFragment<PopupRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-open

Present when the tooltip is open.

-
data-closed

Present when the tooltip is closed.

-
data-align

Indicates how the popup is aligned relative to specified side.

'start' | 'center' | 'end'
data-instant

Present if animations should be instant.

'delay' | 'dismiss' | 'focus'
data-side

Indicates which side the popup is positioned relative to the trigger.

'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'
data-starting-style

Present when the tooltip begins animating in.

-
data-ending-style

Present when the tooltip is animating out.

-

TooltipArrow

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<PopupRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-open

Present when the tooltip is open.

-
data-closed

Present when the tooltip is closed.

-
data-uncentered

Present when the tooltip arrow is uncentered.

-
data-align

Indicates how the popup is aligned relative to specified side.

'start' | 'center' | 'end'
data-instant

Present if animations should be instant.

'delay' | 'dismiss' | 'focus'
data-side

Indicates which side the popup is positioned relative to the trigger.

'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

TooltipViewport

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<PopupRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-activation-direction

Indicates the direction from which the popup was activated. This can be used to create directional animations based on how the popup was triggered. Contains space-separated values for both horizontal and vertical axes.

`${'left' | 'right' | ''} ${'down' | 'up' | ''}`
data-current

Applied to the direct child of the viewport when no transitions are present or the new content when it's entering.

-
data-instant

Present if animations should be instant.

'delay' | 'dismiss' | 'focus'
data-previous

Applied to the direct child of the viewport that contains the exiting content when transitions are present.

-
data-transitioning

Indicates that the viewport is currently transitioning between old and new content.

-
CSS variableType
--popup-height

The height of the parent popup. This variable is placed on the 'previous' container and stores the height of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.

\`\`
--popup-width

The width of the parent popup. This variable is placed on the 'previous' container and stores the width of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.

\`\`

TooltipHandle