Skip to content

Surfaces

Tooltip

Bit.BlazorUITipHint

Tooltip briefly describes an unlabeled control or adds a bit of information to a labeled one, in a small surface shown next to what it belongs to. It is shown on hover and on focus, or on a press of the anchor with either the pointer or the keyboard, after delays of your choosing, on any of twelve positions around its anchor, with an arrow pointing back at it. It holds a text or any content you give it, can be made hoverable so the pointer may travel into it, answers a touch with a tap or a long press, is dismissed by the Escape key, names or describes its anchor to a screen reader, shares its delays with the tooltips around it, and can be driven from your own code through a two-way bound state or its Show, Hide and Toggle methods.

Notes

The tooltip is laid out entirely in CSS, next to its anchor and inside the flow of the page, which is what makes it free of any positioning pass and of all but one line of JavaScript - the one that copies the relationship onto the anchor. The two things that follow from it are worth knowing before you place one: it is clipped by an ancestor that hides its overflow, and it stays on the side you asked for rather than flipping to the one with room on it. A surface that has to escape an overflow, find its own room on the screen, or hold something to click or type in is a BitCallout rather than a tooltip.

Usage

Every example is live. Open its code to see exactly what produced the component running underneath.

Basic

Text is what the tooltip says, and whatever is put inside the tooltip is the anchor it belongs to and is shown next to. Out of the box the tooltip is shown when the pointer enters the anchor and when the keyboard reaches it, and is hidden again when both of them have left. IsEnabled turns the tooltip off without touching the anchor, and hides one that is already shown. A tooltip left without a text and without a template is no tooltip at all: no surface is put on the page for it and nothing points at it. Because the tooltip listens on the element it wraps the anchor in rather than on the anchor itself, a disabled control - which answers no pointer of its own - still has a tooltip that explains why it is disabled.

Position

Position is the place the tooltip takes around its anchor: one of the four sides, each of them also available lined up with either end of the anchor rather than centred on it. The arrow follows the tooltip and keeps pointing back at the anchor from wherever it lands. All twelve are shown open here at once; they are the same tooltip in every other respect.

Triggers

Switches decide what shows the tooltip and what takes it away. ShowOnHover (on by default) answers the pointer entering the anchor and ShowOnFocus (on by default as well) answers the keyboard reaching it; the two are kept apart, so a pointer leaving an anchor the keyboard is still on does not take the tooltip away with it, and a click that focuses the anchor is not mistaken for a tab that reached it. ShowOnClick turns the anchor into a toggle, and HideOnClick instead has an ordinary hover tooltip step aside the moment the anchor is pressed, which is what a button that opens something else owes the reader. Both of them answer the keyboard the way they answer the pointer: Enter and Space on the anchor are a press of it, so a click-driven tooltip can be opened without a pointer at all. A tooltip opened that way stays until the anchor is pressed again, Escape is pressed on it, or the focus leaves it - which a click elsewhere on the page and a Tab away from it both come down to. On a touch screen there is no pointer that hovers, so a tap shows the tooltip and it hides itself again after TouchHideDelay milliseconds; TouchShowDelay makes the tooltip a long press of its own, so that a tap that only meant to press the anchor leaves it out of it, and NoTouch leaves the touch to the anchor altogether.

Delay

ShowDelay is how long the pointer has to rest on the anchor before the tooltip is shown, which keeps a pointer merely crossing a row of controls from lighting all of them up. HideDelay is how long the tooltip stays behind once the pointer has left, which stops it flickering when the pointer slips off an edge and comes back. Both are cancelled by the opposite move arriving first, and the show delay is for the pointer alone: a tooltip reached with the keyboard or opened by a click is shown at once, since it was asked for.

Grouping

BitTooltipGroup makes a row of tooltips behave as the one piece of chrome a reader takes them for. It hands its ShowDelay and HideDelay to every tooltip inside it that does not set one of its own, keeps only one of them on the screen at a time (unless AllowMultiple says otherwise), and drops the show delay for SkipDelay milliseconds after one of them has been hidden - once the reader has stopped to read the first tooltip they are reading the row rather than crossing it, and waiting again only reads as lag. Rest on the first button below, then walk along the rest of them.

Arrow & offset

The arrow points from the tooltip back at the anchor. HideArrow leaves it out, ArrowSize sets the length of the side of the square it is drawn from, and Offset is the distance in pixels the tooltip is held off the anchor, which is also the room the arrow is drawn in - an arrow that reaches further than that is given the room it needs anyway. Leaving the last two unset keeps whatever the theme gives them.

Interactive

Interactive lets the pointer travel into the tooltip and rest there without it being hidden, which is what WCAG 1.4.13 asks of anything shown on hover and what a tooltip whose text has to be read across, magnified or selected needs. The gap between the anchor and the tooltip is bridged, so the pointer never leaves the component on the way over, and a pointer released inside the tooltip is not taken for a click on the anchor. A tooltip that holds something to click or to type in is a callout rather than a tooltip: it has to take the focus, which a tooltip never does.

Custom content

Template is the content of the tooltip when a plain Text is not enough, and Anchor (an alias of ChildContent) is what it belongs to. Both are ordinary render fragments, so anything may go in them - the tooltip is sized to what it holds.

Max width

A tooltip is only as wide as what it holds, up to a cap the theme sets, past which the text wraps onto another line instead of the tooltip running on across the screen. MaxWidth takes any CSS length to set that cap yourself, and the value "none" takes it off for the tooltip that is meant to be a single line however long it is.

Dismissal

The Escape key hides the tooltip while the keyboard is on the anchor, without the focus having to move away first - the "dismissible" half of WCAG 1.4.13, and what a tooltip that covers what is underneath it owes the reader. It stays dismissed until the anchor is left and reached again, rather than coming straight back. NoDismissOnEscape turns that off, which is only for a tooltip that obscures nothing. Tab to either of these and press Escape. A tooltip a press of the anchor opened is dismissed by the focus leaving it as well, since a click somewhere else on the page and a Tab away from the anchor both take the focus off it - a pointer still resting on the anchor keeps it, having asked for it in its own right.


Accessibility

Relationship says what the tooltip is to its anchor. Description, the default, points an aria-describedby at it, which is the tooltip that adds something to a control that already has a name. Label points an aria-labelledby at it instead, for the icon-only button whose only name the tooltip is. None leaves it out of the accessibility tree, for the tooltip that only repeats what the anchor already says. The relationship is declared for as long as there is a tooltip to declare it with, not only while it is on the screen, so a screen reader has the text the moment the anchor is reached. A description is computed on the element that has the focus, and the element the tooltip declares the relationship on is the container it wraps the anchor in, so the same relationship is copied onto the first focusable control inside that container - the button the reader actually lands on. An anchor that names a description or a label of its own keeps it. TooltipId is the id of the element the text lands in: point an anchor of your own at it where there is nothing focusable for the copy to land on, or where something other than the first control is what the tooltip belongs to.

Lazy rendering

LazyRender keeps the content of the tooltip out of the DOM until the tooltip is first shown, and keeps it rendered from then on, so a page carrying many tooltips over costly content is not paying for all of them up front. The timestamp below is taken while the content renders: the lazy one is stamped the moment you first hover it, the other one the moment the page loaded.

Binding

DefaultIsShown is the state the tooltip starts in and then manages itself. @bind-IsShown hands that state to your own field instead: the tooltip keeps answering its triggers and reports every change back, so the two stay in step. Handing IsShown over without binding it makes the state entirely yours - the triggers are then left alone and only your code shows and hides the tooltip.

Methods

A reference to the component gives you Show, Hide and Toggle, which act at once and regardless of the triggers and the delays the tooltip is configured with. They are what a tooltip driven by something happening elsewhere on the page needs - a validation that has just failed, a step of a tour - rather than by the pointer on its anchor.

Events

OnShow and OnHide report the tooltip changing state, and OnToggle reports both of them with the new state, so a single handler can follow the tooltip. They are called once the delays have run out and the state has actually changed, never for a trigger that was cancelled before it landed.


Advanced

Everything above on one tooltip, to try the combinations out on.





 






Color

Color paints the surface of the tooltip and the arrow along with it, out of the same palette the rest of the library reads, so the text on it stays legible in every theme. The eight semantic colors carry a meaning worth spending on a tooltip - an error, a warning, a confirmation - and the neutral background, foreground and border families are there for a tooltip that has to sit against a particular surface.

Size

Size moves the tooltip along the type ramp the library shares and pads it to match. A tooltip is small chrome by nature, so the one you do not size sits at the small end of that ramp already; Medium and Large are for the tooltip whose text is the point rather than a footnote.

Style & Class

Style and Class reach the root element, and Styles and Classes reach the parts inside it - the root, the wrapper the tooltip is placed by, the tooltip surface itself and the arrow - so a single tooltip can be reshaped without a rule that catches every other one on the page. NoAnimation takes the fade off, for a tooltip that should simply be there, and ZIndex lifts the surface over a neighbour that the page would otherwise paint on top of it - the tooltip is stacked inside the flow of the page rather than at the end of the body. FullWidth is for the block-level anchor: the tooltip wraps what it belongs to in an element laid out inline, which would otherwise shrink a text field or a stretched button to the width of its own content.

Styles:

Classes:

NoAnimation:

ZIndex:

FullWidth:

RTL

Set Dir to Rtl to lay the content of the tooltip out right-to-left. The positions are named for the sides of the screen rather than for the reading order, so Left is the left of the anchor in either direction. MirrorInRtl swaps the two sides while the direction is right-to-left, so that a tooltip meant to follow the text - a hint beside a field, say - lands on the side the reader starts at; leave it off for one that has to stay where it is put.

API

Every parameter, public member, sub-class and enum this component exposes.

BitTooltip parameters

Name Type Default value Description
Anchor RenderFragment? null Child content of component, the content that the Tooltip will apply to.
ArrowSize int? null The size in pixels of the arrow that points at the anchor, which is the length of the side of the square it is drawn from. Leaving it unset keeps the size the theme gives it.
ChildContent RenderFragment? null Child content of component, the content that the Tooltip will apply to.
Classes BitTooltipClassStyles? null Custom CSS classes for different parts of the BitTooltip.
Color BitColor? null The general color of the tooltip, which colors its surface and the arrow along with it.
DefaultIsShown bool? null Default value of the IsShown.
FullWidth bool false Expands the tooltip's own element to 100% of the available width, so that the anchor inside it keeps the width it would have had without a tooltip around it. The tooltip wraps its anchor in an element laid out inline, which would otherwise shrink a block-level anchor to its content.
HideArrow bool false Hides the arrow of tooltip.
HideDelay int 0 Delay (in milliseconds) before hiding the tooltip. It is the grace an interactive tooltip needs while the pointer crosses the gap between the anchor and the tooltip, and the pause that keeps a tooltip from flickering while the pointer skims across a row of anchors. Leaving it alone inside a BitTooltipGroup takes the delay the group sets.
HideOnClick bool false Hides the tooltip when the anchor is pressed, which is what a tooltip on a control that does something when pressed owes the reader. It answers Enter and Space the way it answers the pointer. A tooltip the press is meant to open and close instead is ShowOnClick, which takes the press over when it is on.
Interactive bool false Lets the pointer travel into the tooltip and stay there without it being hidden, which is what WCAG 1.4.13 asks of content shown on hover. The gap between the anchor and the tooltip is bridged, so the pointer never leaves the component on its way over.
IsShown bool false The visibility state of the tooltip.
IsShownChanged EventCallback<bool> The callback that is called when the visibility state of the tooltip changes.
LazyRender bool false Holds the content of the tooltip out of the DOM until the tooltip is first shown, and keeps it rendered from then on.
MaxWidth string? null The maximum width of the tooltip as a CSS value (e.g. "20rem"), beyond which its text wraps onto another line instead of the tooltip growing wider. A value of "none" takes the cap off.
MirrorInRtl bool false Mirrors the position of the tooltip along the horizontal axis while the direction is right to left, so that a position named for one side of the anchor lands on the side the reader starts at. The positions are named for the sides of the screen rather than for the reading order, so Left is the left of the anchor in either direction unless this is turned on.
NoAnimation bool false Removes the fade the tooltip is shown and hidden with, so that it simply appears.
NoDismissOnEscape bool false Keeps the Escape key from dismissing the tooltip. Dismissing content shown on hover or focus without moving either of them is what WCAG 1.4.13 asks for, so only turn it off for a tooltip that obscures nothing.
NoTouch bool false Keeps a touch or a pen from showing the tooltip at all, leaving the anchor to answer the tap alone. Turn it on for a tooltip that only repeats what a touch user can already read.
Offset int? null The distance in pixels between the anchor and the tooltip, which is also the room the arrow is drawn in. An arrow that reaches further than this is given the room it needs anyway, so this is the smallest distance rather than the exact one. Leaving it unset keeps the distance the theme gives it.
OnHide EventCallback The callback that is called when the tooltip is hidden.
OnShow EventCallback The callback that is called when the tooltip is shown.
OnToggle EventCallback<bool> The callback that is called when the tooltip is shown or hidden, with the new state.
Position BitTooltipPosition BitTooltipPosition.Top The position of tooltip around its anchor.
Relationship BitTooltipRelationship BitTooltipRelationship.Description What the tooltip is to the anchor it belongs to, which decides whether the anchor is given an aria-describedby, an aria-labelledby or neither. The relationship is declared on the element the anchor is wrapped in and copied onto the first focusable control inside it, since a name or a description is computed on the element that has the focus.
ShowDelay int 0 Delay (in milliseconds) before showing the tooltip. It applies to the pointer only: a tooltip reached with the keyboard or opened by a click is shown at once. Leaving it alone inside a BitTooltipGroup takes the delay the group sets, which the group also drops while another of its tooltips is still fresh in mind.
ShowOnClick bool false Turns the anchor into a toggle for the tooltip, which is shown by a press of it and taken away by the next one. Enter and Space are a press of the anchor as much as the pointer is, and what dismisses it besides a second press is the Escape key and the focus leaving the anchor. It takes the press over from HideOnClick.
ShowOnFocus bool true Determines whether the tooltip is shown when the anchor takes the focus, so that a tooltip reached with the keyboard is shown the way it is to a pointer. A focus that follows a press of the pointer is left to the pointer, the way :focus-visible does it in CSS.
ShowOnHover bool true Determines whether the tooltip is shown while the pointer is over the anchor. The hover and the focus are kept apart, so a pointer leaving an anchor the keyboard is still on does not take the tooltip away with it.
Size BitSize? null The size of the tooltip, which sets the size of its text and the padding around it.
Styles BitTooltipClassStyles? null Custom CSS styles for different parts of the BitTooltip.
Template RenderFragment? null The content you want inside the tooltip.
Text string? null The text of tooltip to show.
TouchHideDelay int 1500 The time in milliseconds a tooltip shown by a touch stays before it hides itself. A touch leaves no pointer behind that can leave the anchor again. Zero leaves it shown until something else hides it.
TouchShowDelay int 0 The time in milliseconds a touch has to rest on the anchor before the tooltip is shown, which turns a tap that only meant to press the anchor into a press that leaves the tooltip out of it. Zero shows the tooltip on the tap itself.
ZIndex int? null The stacking order of the tooltip surface and its arrow. Leaving it unset keeps the one the theme gives every popup surface in the library.

BitTooltip public members

Name Type Default value Description
Show Task Shows the tooltip programmatically, at once and regardless of the triggers it is configured with, unless it is disabled.
Hide Task Hides the tooltip programmatically, at once and regardless of the delays it is configured with.
Toggle Task Toggles the tooltip to show/hide it.
TooltipId string The id of the element the text of the tooltip is rendered in, which is what an anchor of your own points its aria-describedby or aria-labelledby at.

BitComponentBase parameters

Name Type Default value Description
AriaLabel string? null Gets or sets the accessible label for the component, used by assistive technologies.
Class string? null Gets or sets the CSS class name(s) to apply to the rendered element.
Dir BitDir? null Gets or sets the text directionality for the component's content.
ForceAnimation bool false Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested.
HtmlAttributes Dictionary<string, object> new Dictionary<string, object>() Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters.
Id string? null Gets or sets the unique identifier for the component's root element.
IsEnabled bool true Gets or sets a value indicating whether the component is enabled and can respond to user interaction.
Style string? null Gets or sets the CSS style string to apply to the rendered element.
TabIndex string? null Gets or sets the tab order index for the component when navigating with the keyboard.
Visibility BitVisibility BitVisibility.Visible Gets or sets the visibility state (visible, hidden, or collapsed) of the component.

BitComponentBase public members

Name Type Default value Description
UniqueId Guid Guid.NewGuid() Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed.
RootElement ElementReference Gets the reference to the root HTML element associated with this component.

BitTooltipGroup properties

Groups the tooltips inside it so that they share their delays, so that the second of them is shown without its delay while the first is still fresh in mind, and so that only one of them is on the screen at a time. It renders nothing of its own.

Name Type Default value Description
AllowMultiple bool false Lets more than one tooltip of the group be on the screen at a time. A group shows one tooltip at a time by default, which is what a row of controls with a tooltip each needs.
ChildContent RenderFragment? null The tooltips the group is around.
HideDelay int? null The delay in milliseconds before hiding, for every tooltip in the group that does not set one of its own.
ShowDelay int? null The delay in milliseconds before showing, for every tooltip in the group that does not set one of its own.
SkipDelay int 300 How long in milliseconds after a tooltip of the group has been hidden another one of them is shown at once rather than waiting out the show delay. Zero makes every tooltip wait out its own delay.

BitTooltipClassStyles properties

Name Type Default value Description
Root string? null Custom CSS classes/styles for the root element of the BitTooltip.
TooltipWrapper string? null Custom CSS classes/styles for the tooltip wrapper of the BitTooltip.
Tooltip string? null Custom CSS classes/styles for the tooltip of the BitTooltip.
Arrow string? null Custom CSS classes/styles for the arrow of the BitTooltip.

BitTooltipPosition enum

Name Value Description
Top 0 The position of tooltip top of its anchor
TopLeft 1 The position of tooltip top left of its anchor
TopRight 2 The position of tooltip top right of its anchor
RightTop 3 The position of tooltip right top of its anchor
Right 4 The position of tooltip right of its anchor
RightBottom 5 The position of tooltip right bottom of its anchor
BottomRight 6 The position of tooltip bottom right of its anchor
Bottom 7 The position of tooltip bottom of its anchor
BottomLeft 8 The position of tooltip bottom left of its anchor
LeftBottom 9 The position of tooltip left bottom of its anchor
Left 10 The position of tooltip left of its anchor
LeftTop 11 The position of tooltip left top of its anchor

BitTooltipRelationship enum

Name Value Description
Description 0 The tooltip adds information to an anchor that already has a name of its own, and is pointed at with aria-describedby.
Label 1 The tooltip is the name of an anchor that has none of its own - an icon-only button, above all - and is pointed at with aria-labelledby.
None 2 The tooltip is left out of the accessibility tree altogether, for the case where the anchor already carries the same text by another route.

BitColor enum

Name Value Description
Primary 0 Primary general color.
Secondary 1 Secondary general color.
Tertiary 2 Tertiary general color.
Info 3 Info general color.
Success 4 Success general color.
Warning 5 Warning general color.
SevereWarning 6 SevereWarning general color.
Error 7 Error general color.
PrimaryBackground 8 Primary background color.
SecondaryBackground 9 Secondary background color.
TertiaryBackground 10 Tertiary background color.
PrimaryForeground 11 Primary foreground color.
SecondaryForeground 12 Secondary foreground color.
TertiaryForeground 13 Tertiary foreground color.
PrimaryBorder 14 Primary border color.
SecondaryBorder 15 Secondary border color.
TertiaryBorder 16 Tertiary border color.

BitSize enum

Name Value Description
Small 0 The small size tooltip.
Medium 1 The medium size tooltip.
Large 2 The large size tooltip.

BitVisibility enum

Name Value Description
Visible 0 The content of the component is visible.
Hidden 1 The content of the component is hidden, but the space it takes on the page remains (visibility:hidden).
Collapsed 2 The component is hidden (display:none).

BitDir enum

Name Value Description
Ltr 0 Ltr (left to right) is to be used for languages that are written from the left to the right (like English).
Rtl 1 Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic).
Auto 2 Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element.

Feedback

Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.