2021-10-22 19:32:39 +08:00
---
2021-10-25 15:21:08 +08:00
title: Tooltip
2021-10-22 19:32:39 +08:00
lang: en-US
---
2021-09-17 00:18:50 +08:00
# Tooltip
2020-08-13 15:18:26 +08:00
Display prompt information for mouse hover.
2021-09-17 00:18:50 +08:00
## Basic usage
2020-08-13 15:18:26 +08:00
Tooltip has 9 placements.
:::demo Use attribute `content` to set the display content when hover. The attribute `placement` determines the position of the tooltip. Its value is `[orientation]-[alignment]` with four orientations `top` , `left` , `right` , `bottom` and three alignments `start` , `end` , `null` , and the default alignment is null. Take `placement="left-end"` for example, Tooltip will display on the left of the element which you are hovering and the bottom of the tooltip aligns with the bottom of the element.
2021-09-04 19:29:28 +08:00
2021-09-17 00:18:50 +08:00
tooltip/basic
2020-08-13 15:18:26 +08:00
2021-09-04 19:29:28 +08:00
:::
2020-08-13 15:18:26 +08:00
2021-09-17 00:18:50 +08:00
## Theme
2020-08-13 15:18:26 +08:00
2022-06-04 06:48:44 +08:00
Tooltip has two built-in themes: `dark` and `light` .
2022-01-04 09:15:15 +08:00
:::tip
To use customized theme, you will have to known where your tooltip is rendered into, if your tooltip is rendered into the root element, you will need to set the css rule globally.
2022-03-24 21:22:46 +08:00
It is recommended that not using linear gradient background color when you using customized theme and showing the arrow at the same time, because the popup arrow and the content are two different elements,
2022-01-04 09:15:15 +08:00
the popup arrow's style needs to be set individually, and when it comes to the gradient background color, it might seem a little bit weird.
:::
2020-08-13 15:18:26 +08:00
:::demo Set `effect` to modify theme, and the default value is `dark` .
2021-09-04 19:29:28 +08:00
2021-09-17 00:18:50 +08:00
tooltip/theme
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
2021-09-17 00:18:50 +08:00
## More Content
2020-08-13 15:18:26 +08:00
Display multiple lines of text and set their format.
:::demo Override attribute `content` of `el-tooltip` by adding a slot named `content` .
2021-09-04 19:29:28 +08:00
2021-09-17 00:18:50 +08:00
tooltip/rich-content
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
2021-09-17 00:18:50 +08:00
## Advanced usage
2020-08-13 15:18:26 +08:00
In addition to basic usages, there are some attributes that allow you to customize your own:
`transition` attribute allows you to customize the animation in which the tooltip shows or hides, and the default value is el-fade-in-linear.
`disabled` attribute allows you to disable `tooltip` . You just need set it to `true` .
2022-01-04 09:15:15 +08:00
In fact, Tooltip is an extension based on [ElPopper ](https://github.com/element-plus/element-plus/tree/dev/packages/components/popper ), you can use any attribute that are allowed in ElPopper.
2020-08-13 15:18:26 +08:00
:::demo
2021-09-04 19:29:28 +08:00
2021-09-17 00:18:50 +08:00
tooltip/advanced-usage
2020-08-13 15:18:26 +08:00
2021-09-04 19:29:28 +08:00
:::
2020-08-13 15:18:26 +08:00
:::tip
2021-09-17 00:18:50 +08:00
2020-08-13 15:18:26 +08:00
The `router-link` component is not supported in tooltip, please use `vm.$router.push` .
Disabled form elements are not supported for Tooltip, more information can be found at [MDN ](https://developer.mozilla.org/en-US/docs/Web/Events/mouseenter ). You need to wrap the disabled form element with a container element for Tooltip to work.
2021-09-17 00:18:50 +08:00
2020-08-13 15:18:26 +08:00
:::
2022-01-04 09:15:15 +08:00
## HTML as content
The content attribute can be set to HTML string.
:::warning
2022-01-25 16:10:49 +08:00
Although `content` property supports HTML strings, dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to [XSS attacks ](https://en.wikipedia.org/wiki/Cross-site_scripting ). So when `raw-content` is on, please make sure `content` is trusted, and **never** assign user-provided `content` .
2022-01-04 09:15:15 +08:00
:::
:::demo
tooltip/html-content
:::
## Virtual triggering
Sometimes we want to render the tooltip on some other trigger element,
we can separate the trigger and the content.
2022-01-11 14:34:40 +08:00
:::tip
Virtual triggering tooltip is controlled component, so that you will have to control the visibility of the tooltip your own
when this happens, **YOU WILL NOT** be able to close the tooltip by clicking somewhere else.
:::
2022-01-04 09:15:15 +08:00
:::demo
tooltip/virtual-trigger
:::
## Singleton
Tooltip can also be singleton, which means you can have multiple trigger with only one tooltip instance, this function is implemented based on `Virtual triggering`
2022-01-11 14:34:40 +08:00
:::tip
Known issue: when using singleton, the popup will be bouncing out from unexpected places
:::
2022-01-04 09:15:15 +08:00
:::demo
tooltip/singleton
:::
## Controlled
2022-01-20 15:28:18 +08:00
Tooltip can be controlled by the parent component, by using `v-model:visible` you can implement two way binding.
2022-01-04 09:15:15 +08:00
:::demo
tooltip/controlled
:::
## Animations
Tooltip can be customized animated, you can set the the desired animation function as you desired.
:::demo
tooltip/animations
:::
2021-09-17 00:18:50 +08:00
## Attributes
2021-09-04 19:29:28 +08:00
2022-02-04 14:59:58 +08:00
| Attribute | Description | Type | Accepted Values | Default |
| ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------- | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
| append-to | which element the tooltip CONTENT appends to | CSSSelector \| HTMLElement | — | #el -popper-container-[randomValue] |
| effect | Tooltip theme, built-in theme: `dark` / `light` | string | string | dark |
| content | display content, can be overridden by `slot#content` | String | — | — |
| raw-content | whether `content` is treated as HTML string | boolean | — | false |
| placement | position of Tooltip | string | top/top-start/top-end/bottom/bottom-start/bottom-end/left/left-start/left-end/right/right-start/right-end | bottom |
| visible / v-model:visible | visibility of Tooltip | boolean | — | false |
| disabled | whether Tooltip is disabled | boolean | — | false |
| offset | offset of the Tooltip | number | — | 0 |
| transition | animation name | string | — | el-fade-in-linear |
| visible-arrow (will deprecate in 2.1.0 ) | whether an arrow is displayed. For more information, check [ElPopper ](https://github.com/element-plus/element-plus/tree/dev/packages/components/popper ) page | boolean | — | true |
| popper-options | [popper.js ](https://popper.js.org/documentation.html ) parameters | Object | refer to [popper.js ](https://popper.js.org/documentation.html ) doc | `{ boundariesElement: 'body', gpuAcceleration: false }` |
| show-after | delay of appearance, in millisecond | number | — | 0 |
| show-arrow | whether the tooltip content has an arrow | boolean | true / false | true |
2022-04-13 22:15:37 +08:00
| hide-after | delay of disappear, in millisecond | number | — | 200 |
2022-02-04 14:59:58 +08:00
| auto-close | timeout in milliseconds to hide tooltip | number | — | 0 |
| manual | whether to control Tooltip manually. `mouseenter` and `mouseleave` won't have effects if set to `true` | boolean | — | false |
| popper-class | custom class name for Tooltip's popper | string | — | — |
| enterable | whether the mouse can enter the tooltip | Boolean | — | true |
| tabindex | [tabindex ](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex ) of Tooltip | number | — | 0 |
| teleported | whether tooltip content is teleported, if `true` it will be teleported to where `append-to` sets | boolean | true / false | true |
| trigger | How should the tooltip be triggered (to show) | string | hover / click / focus / contextmenu | hover |
| virtual-triggering | Indicates whether virtual triggering is enabled | boolean | — | false |
| virtual-ref | Indicates the reference element to which the tooltip is attached | HTMLElement | — | — |
2021-10-04 08:26:51 +08:00
## Slots
2022-01-11 14:34:40 +08:00
| Name | Description |
| ------- | -------------------------------------- |
| — | Tooltip triggering & reference element |
| content | customize content |