-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: modifier byAttribute for dynamic attribute autofocuse #1
Conversation
@botre ping |
Hello, Thank you for your pull request! Am I missing something here? <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
</head>
<body>
<div id="app">
<input type="text" />
<input type="text" :autofocus="af" />
</div>
<script src="https://unpkg.com/vue/dist/vue.min.js"></script>
<script>
new Vue({
el: "#app",
data() {
return {
af: true
};
}
});
</script>
</body>
</html> |
@botre Hi
you all say right, but I have a situation in which I need to clearly trigger a focus event, like this) |
Oh I see, What do you think about the following implementation? // Register a global custom directive called `v-focus`
const directive = {
// When the bound element is inserted into the DOM...
inserted: function(el, binding) {
if (typeof binding.value !== "undefined" && !binding.value) {
return;
}
el.focus();
}
};
export default directive; <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Demo</title>
</head>
<body>
<div id="app">
<input v-autofocus="isDesktop" type="text" />
</div>
<script src="https://unpkg.com/vue/dist/vue.min.js"></script>
<script src="./dist/vue-autofocus-directive.js"></script>
<script>
Vue.directive("autofocus", window["vue-autofocus-directive"].default);
new Vue({
el: "#app",
data() {
return {
isDesktop: true
};
}
});
</script>
</body>
</html> BR |
@botre Yes, your decision is more elegant, but unfortunately it carries less information about actions, although it increases your imagination) |
Merged into master, built & deployed to NPM as 1.0.2. Thank you! |
No description provided.