Tooltip
Tooltips provide supplementary text information for a specific element, enhancing the comprehension of its function or purpose.
Usage
Import the component:
import 'mdui/components/tooltip.js';
Import the TypeScript type:
import type { Tooltip } from 'mdui/components/tooltip.js';
Example:
<mdui-tooltip content="Plain tooltip">
<mdui-button>button</mdui-button>
</mdui-tooltip>
Examples
Plain Text Tooltip
By default, the tooltip displays plain text. The content
attribute specifies the tooltip content.
Alternatively, the content
slot can also be used for this purpose.
Rich Text Tooltip
For a rich text tooltip, set the variant
attribute to rich
. The tooltip's title and content can be specified using the headline
and content
attributes, respectively.
Alternatively, the headline
and content
slots can be used to specify the tooltip's title and content. The action
slot is used to specify the tooltip's action button.
Placement
The placement
attribute sets the tooltip's position.
Trigger Method
The trigger
attribute determines the trigger method for the tooltip.
Open/Close Delay
When the trigger method is hover
, the open-delay
and close-delay
attributes set the opening and closing delays, respectively. The unit is in milliseconds.
Disabled State
The disabled
attribute disables the tooltip.
API
Properties
Attribute | Property | Reflect | Type | Default |
---|---|---|---|---|
variant | variant | 'plain' | 'rich' | 'plain' | |
Defines the tooltip shape. Default is
| ||||
placement | placement | 'auto' | 'top-left' | 'top-start' | 'top' | 'top-end' | 'top-right' | 'bottom-left' | 'bottom-start' | 'bottom' | 'bottom-end' | 'bottom-right' | 'left-start' | 'left' | 'left-end' | 'right-start' | 'right' | 'right-end' | 'auto' | |
Sets the tooltip position. Default is
| ||||
open-delay | openDelay | number | 150 | |
Sets the delay in milliseconds before the tooltip appears on hover. | ||||
close-delay | closeDelay | number | 150 | |
Sets the delay in milliseconds before the tooltip disappears on hover. | ||||
headline | headline | string | - | |
Sets the tooltip title. Only applicable when | ||||
content | content | string | - | |
Sets the tooltip content. Alternatively, use | ||||
trigger | trigger | 'click' | 'hover' | 'focus' | 'manual' | string | 'hover focus' | |
Defines the trigger method. Supports multiple values separated by spaces. Possible values:
| ||||
disabled | disabled | boolean | false | |
Disables the tooltip. | ||||
open | open | boolean | false | |
Opens the tooltip. |
Events
Name |
---|
open |
Emitted when the tooltip starts to open. Can be prevented with |
opened |
Emitted after the tooltip has opened and the animations are completed. |
close |
Emitted when the tooltip starts to close. Can be prevented with |
closed |
Emitted after the tooltip has closed and the animations are completed. |
Slots
Name |
---|
(default) |
Target element that triggers the tooltip. Only the first element in the |
headline |
Title of the tooltip. Effective only when |
content |
Content of the tooltip, can contain HTML. If only plain text is included, can also use |
action |
Button at the bottom of the tooltip. Effective only when |
CSS Custom Properties
Name |
---|
--shape-corner-plain |
Corner radius of the component when |
--shape-corner-rich |
Corner radius of the component when |
--z-index |
The CSS |