question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

prevent click propogation of options

See original GitHub issue

To Reproduce

<!-- method should never be called when clicking an option -->
<div @click="method">

    <!-- this should prevent click propogation of options -->
    <div @click.stop>
        <v-select .../>
    </div>
</div>

Steps to reproduce the behavior:

  1. Have a click listener on an item wrapping v-select
  2. Wrap v-select with a div and use @click.stop
  3. Click the dropdown
  4. Click an option

Expected behavior Clicking an option should not trigger the parent click event, since it is a child of the div that has @click.stop. However, a click event is triggered. One is not for the dropdown itself, maybe because it’s not dynamic? In inspector, the dropdown options are contained within the div, but seem to float outside of it.

@mousedown seems to work for my use case, maybe because @mousedown.prevent is used here?

https://github.com/sagalbot/vue-select/blob/6e9861e787d016239df2f73ddf18bea42704db07/src/components/Select.vue#L67

It would be great if there was a way to also prevent clicks from propogating.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:11

github_iconTop GitHub Comments

16reactions
alex-dowcommented, Aug 31, 2020

This has posed an interesting problem.

Say you have a modal with a backdrop, and user can click backdrop to close modal. In that modal, you also have a dropdown menu, whose length exceeds that of the modal.

In previous versions of vue-select, this did not seem to be an issue. But now, since the click event of an option is bubbled upwards, the modal’s backdrop gets the click, and the modal closes.

0reactions
LucaColombicommented, Nov 8, 2022

I dont know if solve the issue, in a similar situation adding @click.stop="" preserve the select function without propagating the click event to outer components

Read more comments on GitHub >

github_iconTop Results From Across the Web

Event.stopPropagation() - Web APIs | MDN
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Read more >
How to prevent click event propagation - angular dart
1 Answer 1 · Thanks Ted. While this is the way to stop propagating events, it is not easy to apply, especially with...
Read more >
stopPropagation() Event Method - W3Schools
The stopPropagation() method prevents propagation of the same event from being called. Propagation means bubbling up to parent elements or capturing down to ......
Read more >
event.stopPropagation() | jQuery API Documentation
These handlers, therefore, may prevent the delegated handler from triggering by calling event.stopPropagation() or returning false . Example: Kill the bubbling ...
Read more >
The Dangers of Stopping Event Propagation - CSS-Tricks
Stopping propagation should be thought of like canceling an event, and it should only be used with that intent. Perhaps you want to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found