Skip to content

Commit da52280

Browse files
author
Guillaume Chau
committed
Fix #23
1 parent 3b2ada0 commit da52280

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/components/Popover.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ function getDefault (key) {
5050
return value
5151
}
5252
53+
let isIOS = false
54+
if (typeof window !== 'undefined' && typeof navigator !== 'undefined') {
55+
isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream
56+
}
57+
5358
export default {
5459
name: 'VPopover',
5560
@@ -485,12 +490,20 @@ export default {
485490
486491
$_addGlobalEvents () {
487492
if (this.autoHide) {
488-
window.addEventListener('click', this.$_handleWindowClick)
493+
if (isIOS) {
494+
document.addEventListener('touchstart', this.$_handleWindowClick)
495+
} else {
496+
window.addEventListener('click', this.$_handleWindowClick)
497+
}
489498
}
490499
},
491500
492501
$_removeGlobalEvents () {
493-
window.removeEventListener('click', this.$_handleWindowClick)
502+
if (isIOS) {
503+
document.removeEventListener('touchstart', this.$_handleWindowClick)
504+
} else {
505+
window.removeEventListener('click', this.$_handleWindowClick)
506+
}
494507
},
495508
496509
$_updatePopper (cb) {

src/tooltip.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const DEFAULT_OPTIONS = {
1616
offset: 0,
1717
}
1818

19+
const openTooltips = []
20+
1921
export default class Tooltip {
2022
/**
2123
* Create a new Tooltip.js instance
@@ -203,6 +205,7 @@ export default class Tooltip {
203205
)
204206
: []
205207
this._isDisposed = false
208+
this._enableDocumentTouch = events.indexOf('manual') === -1
206209

207210
// set event listeners
208211
this._setEventListeners(this.reference, events, this.options)
@@ -290,6 +293,8 @@ export default class Tooltip {
290293
}
291294
this._isOpen = true
292295

296+
openTooltips.push(this)
297+
293298
// if the tooltipNode already exists, just show it
294299
if (this._tooltipNode) {
295300
this._tooltipNode.style.display = ''
@@ -366,13 +371,21 @@ export default class Tooltip {
366371
return this
367372
}
368373

374+
_noLongerOpen () {
375+
const index = openTooltips.indexOf(this)
376+
if (index !== -1) {
377+
openTooltips.splice(index, 1)
378+
}
379+
}
380+
369381
_hide (/* reference, options */) {
370382
// don't hide if it's already hidden
371383
if (!this._isOpen) {
372384
return this
373385
}
374386

375387
this._isOpen = false
388+
this._noLongerOpen()
376389

377390
// hide tooltipNode
378391
this._tooltipNode.style.display = 'none'
@@ -420,6 +433,8 @@ export default class Tooltip {
420433
this._tooltipNode.parentNode.removeChild(this._tooltipNode)
421434
this._tooltipNode = null
422435
}
436+
} else {
437+
this._noLongerOpen()
423438
}
424439
return this
425440
}
@@ -493,6 +508,12 @@ export default class Tooltip {
493508
})
494509
}
495510

511+
_onDocumentTouch (event) {
512+
if (this._enableDocumentTouch) {
513+
this._scheduleHide(this.reference, this.options.delay, this.options, event)
514+
}
515+
}
516+
496517
_scheduleShow (reference, delay, options /*, evt */) {
497518
// defaults to 0
498519
const computedDelay = (delay && delay.show) || delay || 0
@@ -554,6 +575,15 @@ export default class Tooltip {
554575
};
555576
}
556577

578+
// Hide tooltips on touch devices
579+
if (typeof document !== 'undefined') {
580+
document.addEventListener('touchstart', event => {
581+
for (let i = 0; i < openTooltips.length; i++) {
582+
openTooltips[i]._onDocumentTouch(event)
583+
}
584+
})
585+
}
586+
557587
/**
558588
* Placement function, its context is the Tooltip instance.
559589
* @memberof Tooltip

0 commit comments

Comments
 (0)