Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tooltips with option { trigger: 'manual' } close on touch event anywhere on the page #158

Closed
sebastiankienzl opened this issue Oct 12, 2018 · 1 comment · May be fixed by ajesse11x/cms#3
Labels

Comments

@sebastiankienzl
Copy link

Here is a jsFiddle that reproduces the bug/unexpected behavior: https://jsfiddle.net/sebastiankienzl/g4mo2cv9/

I want to show a tooltip and only close it after a user has interacted with the element it is supposed to give a hint on. For this, I use the v-tooltip directive on an <input>-element with trigger: 'manual' and controll it via a variable in the data of a Vue-Instance. click- and focus-handlers in the <input>-element trigger a function that hides the tooltip. This is a short version of the code:

Template

<input
         type="text"
         maxlength="10"
         @focus="hideTooltip"
         @click="hideTooltip"
         ref="input"
         v-tooltip="{
             content: 'My content.',
             show: showTooltip,
             trigger: 'manual',
             placement: 'bottom',
             offset: 2,
         }">
</input>

JS

new Vue({
  el: "#app",
  data: {
    showTooltip: true,
  },
  methods: {
    hideTooltip() {
    	this.showTooltip = false
    }
  }
})

This works on desktop-browsers but on a phone (and in the device emulator in Chrome), the tooltip closes as soon as any touch event happens on the page. Is this intentional and if so, can I somehow circumvent this?

@towry
Copy link

towry commented Dec 27, 2018

Had the same issue, strange behavior, there seems no option to disable this behavior.

I modified the source code to add an option to disable such behavior.

directives/v-tooltip.js

export const defaultOptions = {
    // ...
    defaultPersist: false,
}
// ...
export function getOptions (options) {
   const result = {
      // ...
      persist: typeof options.persist !== 'undefined' ? options.persist : directive.options.defaultPersist,
   }
}
// lib/tooltip.js

document.addEventListener('touchstart', event => {
		for (let i = 0; i < openTooltips.length; i++) {
			if (!openTooltips[i].options.persist) {
				openTooltips[i]._onDocumentTouch(event)
			}
		}
	}, supportsPassive ? {
        // ...

Usage

<div v-tooltip="{'persist': true}"></div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants