-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
click outside case. Microtasks and addEventListener #9464
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
Comments
Here is examples: Working 2.5.22 https://jsfiddle.net/gormartsen/uz18a0dx/23/ Not working 2.6.3 https://jsfiddle.net/gormartsen/Lrae3jbg/3/ Basically clickOutside is happening after clickInside processed as a result Any suggestions how it can be done for 2.6.x |
Just add |
@yyx990803 Hi Evan. Expected rollback to |
PS I understand that you are busy guy and it's sometimes annoying to respond "stupid" question. Trust me before write down here, I did alot of research (include new code reading and debuging) and this example is very simplified concept of more complicated Vue APP that has multiple components that need to change state if click happen inside another component. If you like, I can expand example to more complicated, but please show some desire to communicate. |
Also, your example has issue on iOS 10.2.1 after click button, clicking outside is not rolling back state to extended false, so click outside is not working at all. |
Oh I didn't notice there's another component. In that case... just attach your document listener in capture mode. |
You'd better set the |
@yyx990803 Yep. It works now. Future visitors, working example is here: https://jsfiddle.net/gormartsen/Lrae3jbg/5/ @yyx990803 With this code there is another issue - iOS 10.2.1 get stuck with "expanded" state and do not react on "click outside" Do you need it filed as separated issue? How to reproduce: click first button, click second button (so far so good) but then clicking on button produce only click outside but not inside. So @click on button is not get fired. On iOS simulator 11.4 - issue exists but in different state. Clicking between components or around them - does not produce clickoutside. on safari 12.0.3 - all is good with onCapture. As far as I understand it can be connected with |
@yyx990803 I get puzzled how come it started to work in such strange way. So I did more debugging and difference is in lifecycle: useCapture = false
useCapture = true
I did tests only in Safari 12.0.3. I don't know if behaviour is different in other browsers.
|
Also there is another "unexpected behaviour" See: https://jsfiddle.net/gormartsen/Lrae3jbg/13/ lifecycle:
WHat is expecting:
What is happening:
|
This is not a support thread. If you have an isolated bug, open a separate issue with a minimal reproduction, showing the bug and the bug only. The behavior has a lot to do with how you decided to implement your logic using a mix of Vue and direct DOM manipulations, so it's no longer a "bug" per se. |
@yyx990803 Sorry to see tension here. I am not looking for support here. I am bringing a feedback to you. I started to dig dipper and as you can see in previous comment - it's not about direct DOM manipulation but revert event processing. Please review it again. I hope you just have a bad day and it's not your usual behaviour. |
We have limited bandwidth, so we require bug reports to be clear, concise and exhibit what exactly Vue is doing wrong. This is about respecting maintainer's time. Your original case does not qualify as a bug, because it involves your custom directive which has specific expectations on DOM state (contains check). This is not fundamentally caused by Vue, because you will have the same problem if your write vanilla js that synchronously removes the button that triggered the click before the event propagates to the document. For your The iOS 10 issue is probably a real problem, and you should file a separate issue with a boiled down reproduction. |
What problem does this feature solve?
Ability to call method when click is outside element(component)
In 2.5.x there was simple way to do via document.addEventListener and el.contains(event.target)
It was useful specially via directive like v-click-outside="componentMethod"
After inspecting live circle in 2.6.x I found that eventListener happen after click processed inside component and event.target.parentElement is null (in case if there is inside click process that change component display)
Let me peripheries it.
In case if we have a component that change it's own rendering and we listen for EventListener click on $el of the component - EventListener function receive event.target of the removed DOM element.
Going back to the root issue.
How we can simply monitor multiple elements that need to change it's own display if user clicked outside element. Like dropdown element for example.
What does the proposed API look like?
Have no idea.
The text was updated successfully, but these errors were encountered: