Skip to content

Commit 755a17b

Browse files
committed
[Tooltip] Tooltips with zero-length texts are never displayed.
1 parent 27be3fa commit 755a17b

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

docs/pages/components/Tooltip.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
The first element appear in `<tooltip>` node will be the trigger element. You can also use `target` to reference it from outside the component.
66

7+
**Note**: Tooltips with zero-length texts are never displayed.
8+
79
Hover over the button below to toggle tooltips.
810

911
```html

src/components/tooltip/Tooltip.vue

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,21 @@
158158
},
159159
show () {
160160
let tooltip = this.$refs.tooltip
161-
if (!this.enable || !this.triggerEl || this.isShown()) {
162-
return
163-
}
164-
if (this.timeoutId > 0) {
165-
clearTimeout(this.timeoutId)
166-
this.timeoutId = 0
167-
} else {
168-
tooltip.className = `${BASE_CLASS} ${this.placement}`
169-
let container = document.querySelector(this.appendTo)
170-
container.appendChild(tooltip)
171-
utils.setTooltipPosition(tooltip, this.triggerEl, this.placement, this.autoPlacement, this.appendTo)
172-
tooltip.offsetHeight
161+
if (this.enable && this.triggerEl && this.text && !this.isShown()) {
162+
if (this.timeoutId > 0) {
163+
clearTimeout(this.timeoutId)
164+
this.timeoutId = 0
165+
} else {
166+
tooltip.className = `${BASE_CLASS} ${this.placement}`
167+
let container = document.querySelector(this.appendTo)
168+
container.appendChild(tooltip)
169+
utils.setTooltipPosition(tooltip, this.triggerEl, this.placement, this.autoPlacement, this.appendTo)
170+
tooltip.offsetHeight
171+
}
172+
utils.addClass(tooltip, SHOW_CLASS)
173+
this.$emit('input', true)
174+
this.$emit('show')
173175
}
174-
utils.addClass(tooltip, SHOW_CLASS)
175-
this.$emit('input', true)
176-
this.$emit('show')
177176
},
178177
hide () {
179178
if (this.isShown()) {

test/unit/specs/Tooltip.spec.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ describe('Tooltip', () => {
8787
vm.$destroy()
8888
})
8989

90+
it('should not show tooltip with empty text', async () => {
91+
let res = Vue.compile('<tooltip v-model="show"><button></button></tooltip>')
92+
let vm = new Vue({
93+
data () {
94+
return {
95+
show: true
96+
}
97+
},
98+
components: {Tooltip},
99+
render: res.render,
100+
staticRenderFns: res.staticRenderFns
101+
}).$mount()
102+
let $el = $(vm.$el)
103+
$el.appendTo('body')
104+
await utils.sleep(200)
105+
expect(document.querySelectorAll('.tooltip').length).to.equal(0)
106+
$el.remove()
107+
vm.$destroy()
108+
})
109+
90110
it('should be able to use custom target', async () => {
91111
let res = Vue.compile('<div><button ref="btn" type="button">btn</button><tooltip text="test" :target="btn" trigger="focus"></tooltip></div>')
92112
let vm = new Vue({
@@ -274,7 +294,7 @@ describe('Tooltip', () => {
274294
})
275295

276296
it('should be able to change trigger in runtime', async () => {
277-
let res = Vue.compile('<tooltip :trigger="trigger"><button></button></tooltip>')
297+
let res = Vue.compile('<tooltip text="test" :trigger="trigger"><button></button></tooltip>')
278298
let vm = new Vue({
279299
data () {
280300
return {

0 commit comments

Comments
 (0)