-
Notifications
You must be signed in to change notification settings - Fork 40
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
Prevent re-focus when unrelated element attribute changes #8
Comments
Hi, thanks for the report. The behavior is technically correct, but undesirable in this case. This happens because in Vue 2.0 there is only one reactive watcher per component (as opposed to watcher per expression in 1.x), so directives receive updates when anything in the host component changes (as opposed to when the expression value changes in 1.x). This can be fixed by comparing old value with a new one in the update handler, and only doing focus/blur when value changes (including the initialization). The question though is whether this would be a breaking change, i.e. whether there is a use case for calling focus/blur on every change. If this would be a breaking change, I'd prefer adding this behavior under a modifier (something like What do you think? |
I can't think of any cases where I'd want the input to automatically receive focus when anything else changes. In cases where that type of behavior is desirable, it's explicitly programmed. Perhaps a modifier would be best, or release a 3.x. I think anybody coming from 1.x would expect the 1.x behavior & not this new 2.x behavior though. |
Released in 2.1.0. |
Take a look at the following fiddle. When the form is submitted, the submit button is disabled temporarily. The attribute change on a seemingly unrelated element is causing vue-focus to re-focus on the text input.
I'm not sure if this is vue-focus's problem, or something I don't understand about how Vue handles rendering DOM updates.
https://jsfiddle.net/simshaun/rhqoL2hn/
Edit
This has something to do with the focus directive hooking into
componentUpdated
. Adding aconsole.log
in it shows that it's being executed even when unrelated elements are changed by Vue.The text was updated successfully, but these errors were encountered: