Tooltip基于popper实现,但是和popper又有以下几点区别:

  • 提供v-model控制manual mode, 届时trigger将会被覆盖
  • 提供default和content两个插槽[slot]
  • 默认showArrow为false
  • 默认placement为top
  • 提供键盘tab控制,tabindex默认为0

默认

<template>
 <y-tooltip content="popper content">
   <y-button>Hover</y-button>
 </y-tooltip>
</template>

<script>
import { defineComponent } from "vue";

export default defineComponent({
 name: "Base",
});
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14

自定义

<template>
 <y-tooltip v-model="visible">
   <y-button @click="updateVisible">Custom</y-button>
   <template #content>
     <span>这里是一个复杂的content, 里面有链接<y-button size="small" type="link" target="_blank" href="www.baidu.com">百度一下</y-button></span>
   </template>
 </y-tooltip>
</template>

<script>
import { defineComponent, ref } from "vue";

export default defineComponent({
 name: "Custom",
 setup() {
   const visible = ref(false);
   const updateVisible = () => {
     visible.value = !visible.value;
   }

   return {
     visible,
     updateVisible,
   };
 }
});
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

禁用态

<template>
 <y-checkbox v-model="disabled">disabled</y-checkbox>
 <y-tooltip :disabled="!disabled">
   <y-button :disabled="disabled" style="margin: 0 12px;">{{ disabled ? 'disabled' : 'enabled'}}</y-button>
   <template #content>
     <span>这里是一个复杂的content, 里面有链接<y-button size="small" type="link" target="_blank" href="www.baidu.com">百度一下</y-button></span>
   </template>
 </y-tooltip>

 <y-tooltip v-if="disabled">
   <y-button disabled>disabled</y-button>
   <template #content>
     <span>这里是一个复杂的content, 里面有链接<y-button size="small" type="link" target="_blank" href="www.baidu.com">百度一下</y-button></span>
   </template>
 </y-tooltip>
 <y-button v-else>enabled</y-button>
</template>

<script>
import { defineComponent, ref } from "vue";

export default defineComponent({
 name: "Disabled",
 setup() {
   const disabled = ref(false);

   return {
     disabled,
   };
 }
});
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

API

Tooltip props 继承Popper props,但有以下改动

PropertyDescriptionTypeAccepted ValuesDefault
modelValuethe visible of tooltip, will override trigger and turn on manual modeBoolean-undefined
show-arrowwhether the popover is with arrowBoolean-false
placementthe placement of popoverStringtop/top-start/top-end/right/right-start/right-end/bottom/bottom-start/bottom-end/left/left-start/left-endtop

Popper props

PropertyDescriptionTypeAccepted ValuesDefault
visiblethe visible of popover, will override trigger and turn on manual modeBoolean-undefined
disabledwhether disabled the popover, when disabled the popover will not be shownBoolean-false
placementthe placement of popoverStringtop/top-start/top-end/right/right-start/right-end/bottom/bottom-start/bottom-end/left/left-start/left-endtop
triggerhow to trigger the popoverStringhover/click/focushover
contentthe content of popoverString--
themethe theme of popoverStringdark/lightdark
hide-hover-popperwhether to hide popper when hover itBoolean-false
hide-on-clickwhether to hide popper when click, only effective when the trigger is clickBoolean-true
show-arrowwhether the popover is with arrowBoolean-true
popper-optionscustom options of popperObject--
popper-classcustom class of popperString--
popper-stylecustom style object of popperObject--
popper-stylecustom style object of popperObject--
classcustom class of triggerObject--
stylecustom style object of triggerObject--
append-to-bodywhether append popper to bodyBoolean-true
auto-closeauto close popper, 0 means do not use auto closeNumber-0
transitionpopper transition nameString-yoga-fade-in-linear

Events

EventDescriptionParameters
update:modelValuetrigger when tooltip visible changevisible: boolean

Slots

NameDescriptionParameters
defaulttooltip trigger element-
contenttooltip content, which will override content props-