diff --git a/dist/vue-focus.common.js b/dist/vue-focus.common.js index 7a7e6a1..1aa44fa 100644 --- a/dist/vue-focus.common.js +++ b/dist/vue-focus.common.js @@ -12,7 +12,12 @@ if (!compatible) { var focus = { inserted: function(el, binding) { - if (binding.value) el.focus(); + if (binding.value) { + el.focus(); + if (binding.modifiers.select) { + el.select(); + } + } else el.blur(); }, @@ -23,7 +28,12 @@ var focus = { } } - if (binding.value) el.focus(); + if (binding.value) { + el.focus(); + if (binding.modifiers.select) { + el.select(); + } + } else el.blur(); }, }; diff --git a/dist/vue-focus.js b/dist/vue-focus.js index 3428f53..9dcc1e1 100644 --- a/dist/vue-focus.js +++ b/dist/vue-focus.js @@ -11,7 +11,12 @@ var focus = { inserted: function(el, binding) { - if (binding.value) el.focus(); + if (binding.value) { + el.focus(); + if (binding.modifiers.select) { + el.select(); + } + } else el.blur(); }, @@ -22,7 +27,12 @@ } } - if (binding.value) el.focus(); + if (binding.value) { + el.focus(); + if (binding.modifiers.select) { + el.select(); + } + } else el.blur(); }, }; diff --git a/dist/vue-focus.min.js b/dist/vue-focus.min.js index 10acd2e..c317614 100644 --- a/dist/vue-focus.min.js +++ b/dist/vue-focus.min.js @@ -1 +1 @@ -!function(e,u){"use strict";u="default"in u?u.default:u;var o="2.1.0",n=/^2\./.test(u.version);n||u.util.warn("VueFocus "+o+" only supports Vue 2.x, and does not support Vue "+u.version);var s={inserted:function(e,u){u.value?e.focus():e.blur()},componentUpdated:function(e,u){u.modifiers.lazy&&Boolean(u.value)===Boolean(u.oldValue)||(u.value?e.focus():e.blur())}},t={directives:{focus:s}};e.version=o,e.focus=s,e.mixin=t}(this.VueFocus={},Vue); \ No newline at end of file +!function(e,o){"use strict";o="default"in o?o.default:o;/^2\./.test(o.version)||o.util.warn("VueFocus 2.1.0 only supports Vue 2.x, and does not support Vue "+o.version);var s={inserted:function(e,o){o.value?(e.focus(),o.modifiers.select&&e.select()):e.blur()},componentUpdated:function(e,o){o.modifiers.lazy&&Boolean(o.value)===Boolean(o.oldValue)||(o.value?(e.focus(),o.modifiers.select&&e.select()):e.blur())}},u={directives:{focus:s}};e.version="2.1.0",e.focus=s,e.mixin=u}(this.VueFocus={},Vue); \ No newline at end of file diff --git a/examples/index.html b/examples/index.html index daef876..5ff31d8 100644 --- a/examples/index.html +++ b/examples/index.html @@ -59,6 +59,21 @@

Example 4: Custom label

NOTE: click on the label to focus the input.

+
+ +

Example 5: Select Text on Focus

+
+
{{ $data }}
+

+ +

+

NOTE: click text input to focus and select text.

+
diff --git a/index.js b/index.js index 20c8336..8dfb558 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,12 @@ if (!compatible) { export var focus = { inserted: function(el, binding) { - if (binding.value) el.focus(); + if (binding.value) { + el.focus(); + if (binding.modifiers.select) { + el.select(); + } + } else el.blur(); }, @@ -20,7 +25,12 @@ export var focus = { } } - if (binding.value) el.focus(); + if (binding.value) { + el.focus(); + if (binding.modifiers.select) { + el.select(); + } + } else el.blur(); }, };