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

Prevent re-focus when unrelated element attribute changes #8

Closed
simshaun opened this issue Nov 13, 2016 · 3 comments
Closed

Prevent re-focus when unrelated element attribute changes #8

simshaun opened this issue Nov 13, 2016 · 3 comments

Comments

@simshaun
Copy link

simshaun commented Nov 13, 2016

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 a console.log in it shows that it's being executed even when unrelated elements are changed by Vue.

@simplesmiler
Copy link
Owner

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 .lazy).

What do you think?

@simshaun
Copy link
Author

simshaun commented Nov 14, 2016

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.

@simplesmiler
Copy link
Owner

Released in 2.1.0.
Demo (using rawgit instead of cdnjs): https://jsfiddle.net/rhqoL2hn/3/

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

2 participants