-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Elements lose focus on re-render when siblings use v-if, even if element is reused #9883
Comments
I will take a look this. |
Duplicate of #6929 |
I think you can also listen to |
Problem is in the patching process. With current before and after vnode structure. updateChilden will |
@dejour Yes, it also causes |
Version
2.6.10
Reproduction link
https://codepen.io/anon/pen/ZZvVWv
Steps to reproduce
Create a component that contains a button or input sandwiched in between two other elements that are both conditionally rendered using v-if against the same piece of data:
Now click the input to try and focus it.
What is expected?
The two conditional elements appear, the input is focused.
What is actually happening?
The input is focused but immediately blurred, the component renders twice, and the conditional elements are hidden. It is impossible to actually focus the input. This is bizarre because the element is the exact same DOM node, you can confirm via logging, and that's what
key
is there to ensure.This example looks silly but it's a real problem when you start trying to build things like autocomplete components, where you want to render an invisible clickable backdrop to add simple "click away" behavior (this is how GitHub does click away, it's the only bullet proof approach I've found especially when you start using portals as well) and you also need to render the autocomplete dropdown when the input is focused.
The text was updated successfully, but these errors were encountered: