Skip to content

Commit fc829eb

Browse files
committedMar 1, 2022
fix #2889 tooltip when append-to-body
1 parent e33d4fa commit fc829eb

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed
 

‎src/components/tooltip/Tooltip.vue

+36-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ export default {
122122
// update wrapper tooltip
123123
const tooltipEl = this.$data._bodyEl.children[0]
124124
tooltipEl.classList.forEach((item) => tooltipEl.classList.remove(item))
125-
if (this.$vnode && this.$vnode.data && this.$vnode.data.staticClass) {
125+
if (
126+
this.$vnode &&
127+
this.$vnode.data &&
128+
this.$vnode.data.staticClass
129+
) {
126130
tooltipEl.classList.add(this.$vnode.data.staticClass)
127131
}
128132
this.rootClasses.forEach((item) => {
@@ -136,17 +140,45 @@ export default {
136140
tooltipEl.classList.add(item)
137141
}
138142
})
139-
tooltipEl.style.width = `${trigger.clientWidth}px`
140-
tooltipEl.style.height = `${trigger.clientHeight}px`
143+
141144
const rect = trigger.getBoundingClientRect()
145+
142146
let top = rect.top + window.scrollY
143147
let left = rect.left + window.scrollX
148+
149+
const quaterHeight = trigger.clientHeight / 2 / 2
150+
151+
switch (this.position) {
152+
case 'is-top':
153+
tooltipEl.style.width = `${trigger.clientWidth}px`
154+
tooltipEl.style.height = `0px`
155+
top -= trigger.clientHeight - quaterHeight
156+
break
157+
case 'is-bottom':
158+
tooltipEl.style.width = `${trigger.clientWidth}px`
159+
tooltipEl.style.height = `0px`
160+
top += quaterHeight
161+
break
162+
case 'is-left':
163+
tooltipEl.style.width = `0px`
164+
tooltipEl.style.height = `${trigger.clientHeight}px`
165+
break
166+
case 'is-right':
167+
tooltipEl.style.width = `0px`
168+
tooltipEl.style.height = `${trigger.clientHeight}px`
169+
left += trigger.clientWidth
170+
break
171+
}
172+
144173
const wrapper = this.$data._bodyEl
145174
wrapper.style.position = 'absolute'
146175
wrapper.style.top = `${top}px`
147176
wrapper.style.left = `${left}px`
177+
wrapper.style.width = `0px`
148178
wrapper.style.zIndex = this.isActive || this.always ? '99' : '-1'
149-
this.triggerStyle = { zIndex: this.isActive || this.always ? '100' : undefined }
179+
this.triggerStyle = {
180+
zIndex: this.isActive || this.always ? '100' : undefined
181+
}
150182
}
151183
},
152184
onClick() {

0 commit comments

Comments
 (0)
Please sign in to comment.