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

Remove 'trigger' requirement #63

Open
bagelbyte opened this issue Nov 2, 2018 · 7 comments
Open

Remove 'trigger' requirement #63

bagelbyte opened this issue Nov 2, 2018 · 7 comments

Comments

@bagelbyte
Copy link

Use case

I'd like to only open the popper programmatically, which I am currently achieving toggling the 'force-show' prop. However when I click on the component, I want to have some things happen in the contents of the reference slot before the click event fires.

Suggestion

Set the 'trigger' prop to accept a empty string '' value (or something along those lines)

props: {
     trigger: {
        type: String,
        default: 'hover',
        validator: value => ['click', 'hover', ''].indexOf(value) > -1
      },
      ...
}
@devWaleed
Copy link

@bagelbyte Can you share how you're using force-show to enable tooltip?

@bagelbyte
Copy link
Author

bagelbyte commented Nov 6, 2018

sure! I use something that looks like this:

<template>
    <div>
        <popper ref="popper" :force-show="showPopper">
            <div class="popover">
                <h1>wazam</h1>
            </div>

            <div slot="reference">
                <h1>shazam</h1>
            </div>
        </popper>    
        <button @click="openPopper">openpopper</button>
    </div>
</template>
<script>
import Popper from 'vue-popperjs'

export default {
    created(){

    },
    components: {
        Popper
    },
    methods: {
        openPopper(){
	    this.showPopper = !this.showPopper
        }
    },
    data(){
        return {
            showPopper: false
        }
    }
}
</script>

But with the configurations as shown above, the popover still appears on hover. I CAN get around it by setting the 'delay-on-mouse-out' and 'delay-on-mouse-over' values to something very large, where hover/clicks effectively are useless and it just opens with the force-show being toggled, but I figure it was better just to bring it up

@generator85
Copy link

This would be very useful, can I add that it would be great if the document-click event would still be fired when no trigger is given.

@geongeorge
Copy link

I have edited your solution to get rid the trigger issue,

Add popper to a dummy div under (or above) the target element.
If the div has zero height, it won't be clickable
You can use 'force-show' prop to toggle it

<h1>shazam</h1>  
<popper ref="popper" :force-show="showPopper">
            <div class="popover">
                <h1>wazam</h1>
            </div>
          <div slot="reference">
                <div></div> <!-- Basically empty -->
            </div>
 </popper>    

<button @click="openPopper">openpopper</button>

@TurboControl
Copy link

Thanks bagelbyte and geongeorge. The reason why I need to use this type of programming method is because I have interactive components inside the popper and if they effectively make the HTML reactive, the popper gets dismissed. I tried to use click.prevent, but that didn't help. It would stop the popper from dismissing, but only if there was a non-reactive change.

I do have success with dynamic reactivity (loading spinner -> show data), but specifically when I insert rows into a table or toggle a row's visibility, the popper dismisses and without error. Using force-show works around this problem.

The side effect of all of this is that the user can no longer dismiss the popper by clicking outside of the popper. They now need to toggle or use a close button. Is there a way I can gain that feature back? Like emit an event clickOutside?

@vq0599
Copy link
Contributor

vq0599 commented Nov 15, 2019

if 'force-show ' was used , don't listener trigger events.

mounted() {
        this.referenceElm = this.reference || this.$slots.reference[0].elm;
        this.popper = this.$slots.default[0].elm;

        // add next line
        if (typeof this.forceShow === 'boolean') return
        

        switch (this.trigger) {
            // ...
        }
    },

It's solution ?

@karakum
Copy link

karakum commented Dec 16, 2019

And what about simultaneously hover&click handlers for touch&desktop. On desktop 'hover' used, on mobile - 'click' used...
Now I set 'hover' type and listen @click to toggle popper 'programmatically'

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

No branches or pull requests

7 participants