Skip to content

Commit f0be5f5

Browse files
authored
fix(auto-tip): add popperClass for AutoTip directive (#3836)
* fix(auto-tip): add popperClass for AutoTip directive * fix(docs): add version infomation
1 parent e02ba37 commit f0be5f5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

examples/sites/demos/pc/app/directives/webdoc/directives-auto-tip.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default {
4242
<li><code>content</code>属性,指定提示的内容,支持传入<code>string</code>,<code>VNode</code> 或<code>VNode 数组</code>。不传入值时,使用当前<code>Dom</code>元素的内容。 </li>
4343
<li><code>effect</code> 属性,指定提示的效果,支持 <code>light</code> 和 <code>dark</code> ,默认是<code>light</code>亮色主题 </li>
4444
<li><code>placement</code> 属性,指定提示的位置,默认值为<code>top</code> 。参见<code>tooltip</code> 组件的<code>placement</code> 属性。 </li>
45+
<li><code>popperClass</code> 属性,设置弹出层的class,该属性在3.28 版本引入 。参见<code>tooltip</code> 组件的<code>popperClass</code> 属性。 </li>
4546
</ul>
4647
2、如果参数为 <code>false</code>,表示禁止自动提示。 <br>
4748
`,
@@ -53,6 +54,7 @@ export default {
5354
<li><code>content</code> property specifies the content of the prompt, which can be passed to <code>string</code>, <code>VNode</code>, or the <code>VNode array </code>. When no value is passed, the contents of the current <code>Dom</code> element are used. </li>
5455
<li><code>effect</code> property, specify the effect of the prompt, support <code>light</code> and <code>dark</code>, default is <code>light</code> bright color theme </li>
5556
<li><code>placement</code> property specifies the placement of the tip. The default value is <code>top</code>. See the <code>placement</code> property of the <code>tooltip</code> component. </li>
57+
<li><code>popperClass</code> attribute, sets the class of the pop-up layer. See <code>tooltip</code> component's <code>popperClass</code> attribute. </li>
5658
</ul>
5759
2. If the parameter is <code>false</code>, the automatic prompt is disabled. <br>
5860
`

packages/vue-directive/src/auto-tip.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface TooltipDirectiveConfig {
1818
content?: string // 自定义提示内容, 支持字符串或 VNode | VNode[], 不支持嵌套的 html 标签
1919
effect?: 'dark' | 'light' // tooltip主题,默认为light
2020
placement?: string
21+
popperClass?: string
2122
}
2223

2324
// 高度计算最多可以允许的误差,修复checkbox的tip提示一直显示的bug(scrollHeight:15,clientHeight:14)
@@ -55,6 +56,12 @@ const isDarkTheme = (currentTarget) => Boolean(currentTarget?.boundingValue?.eff
5556

5657
const getPlacement = (currentTarget) => currentTarget.boundingValue?.placement || 'top'
5758

59+
let oldPopperClass: string[] = []
60+
const getPopperClass = (currentTarget) => {
61+
const cls: string = currentTarget.boundingValue?.popperClass || ''
62+
return cls.split(' ').filter((c) => c)
63+
}
64+
5865
const mouseenterHandler = (e) => {
5966
const currentTarget = e.currentTarget
6067

@@ -73,10 +80,13 @@ const mouseenterHandler = (e) => {
7380
propsData: {
7481
renderContent: () => h('span', { class: 'tiny-directive-tip__content' }, tooltipContent.value),
7582
placement: getPlacement(currentTarget),
76-
effect: isDarkTheme(currentTarget) ? 'dark' : 'light'
83+
effect: isDarkTheme(currentTarget) ? 'dark' : 'light',
84+
popperClass: getPopperClass(currentTarget).join(' ')
7785
},
7886
component: Tooltip
7987
})
88+
89+
oldPopperClass = getPopperClass(currentTarget)
8090
}
8191

8292
const tooltip = globalTooltip.value
@@ -91,6 +101,9 @@ const mouseenterHandler = (e) => {
91101
`is-${isDarkTheme(currentTarget) ? 'light' : 'dark'}`,
92102
`is-${isDarkTheme(currentTarget) ? 'dark' : 'light'}`
93103
)
104+
popperElm.classList.remove(...oldPopperClass)
105+
oldPopperClass = getPopperClass(currentTarget)
106+
popperElm.classList.add(...oldPopperClass)
94107
}
95108

96109
tooltip.show()

0 commit comments

Comments
 (0)