Overview
TheMtTooltip component provides contextual information in a small floating overlay. It appears on hover or focus and automatically positions itself to remain visible within the viewport.
Import
Props
The HTML content to display in the tooltip. Content is automatically sanitized for security.
Delay in milliseconds before showing the tooltip on hover.
Delay in milliseconds before hiding the tooltip after mouse leaves.
Initial placement of the tooltip. Options include:
top,top-start,top-endbottom,bottom-start,bottom-endleft,left-start,left-endright,right-start,right-end
Maximum width of the tooltip in pixels.
Usage
Basic Tooltip
With Icon Trigger
HTML Content
Custom Placement
With Custom Delays
List in Tooltip
Disabled Element with Tooltip
Slot
The trigger element that displays the tooltip on hover/focus.Slot Props:
You must bind all slot props to your trigger element using
v-bind="params":id: Unique identifier for the triggeronFocus: Focus event handleronBlur: Blur event handleronKeydown: Keydown event handleronMouseover: Mouseover event handleronMouseleave: Mouseleave event handleronMousedown: Mousedown event handleronMouseup: Mouseup event handleraria-describedby: ARIA attribute linking to tooltip
Behavior
Show Triggers
The tooltip appears when:- Mouse hovers over the trigger element (after delay)
- Trigger element receives keyboard focus
Hide Triggers
The tooltip disappears when:- Mouse leaves both trigger and tooltip (after delay)
- Trigger element loses focus
- User presses Escape, Space, or Enter keys
- Trigger element is clicked (mousedown)
Hover Persistence
The tooltip remains visible when hovering over the tooltip itself, allowing users to interact with tooltip content or select text.Content Sanitization
Tooltip content is automatically sanitized using DOMPurify to prevent XSS attacks. The following HTML tags are allowed:- Text formatting:
<b>,<strong>,<i>,<em>,<u>,<s> - Structure:
<br>,<ul>,<li> - Media:
<img>,<svg> - Links:
<a>
Positioning
The tooltip uses Floating UI for intelligent positioning:- Initial Placement: Tooltip attempts to position according to the
placementprop - Flip: Automatically flips to opposite side if there isn’t enough space
- Shift: Shifts along the axis to stay within viewport bounds
- Offset: Maintains 8px distance from the trigger element
- Arrow: Includes a directional arrow pointing to the trigger
Accessibility Features
- ARIA Attributes:
role="tooltip"on tooltip elementaria-describedbylinks trigger to tooltip content
- Keyboard Support:
- Tooltip appears on focus for keyboard navigation
- Escape, Space, or Enter keys dismiss the tooltip
- Focus Management: Focus remains on trigger element when tooltip is visible
- Screen Readers: Tooltip content is properly announced via
aria-describedby
Styling
The tooltip uses a dark theme by default with:- Dark background (
--color-elevation-floating-default) - White text (
--color-text-primary-inverse) - Small font size (
--font-size-2xs) - 12px padding
- Rounded corners (
--border-radius-xs) - Directional arrow indicator
Animations
Smooth fade and slide animations:- 150ms transition duration
- Cubic bezier easing for natural motion
- Direction-aware slide based on placement
- Opacity fade for smooth appearance
Best Practices
- Keep it concise: Tooltips should provide brief, helpful information
- Don’t replace labels: Tooltips supplement, not replace, visible labels
- Avoid complex interactions: Tooltips should be informational, not interactive
- Use appropriate delays: Default 300ms works well for most cases
- Consider mobile: Tooltips don’t work well on touch devices; provide alternative access to information
- Don’t hide critical information: Essential information should be visible without hovering
- Wrap disabled elements: Disabled elements don’t trigger events, so wrap them in a container
- Mind the width: Use
maxWidthto prevent overly wide tooltips