Skip to content

Commit

Permalink
Add autofocus prop to UiTextbox and UiAutocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephusPaye committed Jul 4, 2016
1 parent 1f4cfbf commit 85125a2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/UiAutocomplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<input
class="ui-autocomplete-input" :placeholder="placeholder" :name="name"
:id="id" autocomplete="off"
:id="id" autocomplete="off" v-autofocus="autofocus"
@focus="focus" @blur="blur" @keydown.up="highlight(highlightedItem - 1)"
@keydown.down="highlight(highlightedItem + 1)" @keydown.tab="close"
Expand Down Expand Up @@ -61,6 +61,7 @@ import fuzzysearch from 'fuzzysearch';
import UiIcon from './UiIcon.vue';
import UiAutocompleteSuggestion from './UiAutocompleteSuggestion.vue';
import autofocus from '../directives/autofocus';
import HasTextInput from './mixins/HasTextInput';
import ValidatesInput from './mixins/ValidatesInput';
Expand Down Expand Up @@ -92,6 +93,10 @@ export default {
showOnUpDown: {
type: Boolean,
default: true
},
autofocus: {
type: Boolean,
default: false
}
},
Expand Down Expand Up @@ -229,6 +234,10 @@ export default {
UiAutocompleteSuggestion
},
directives: {
autofocus
},
mixins: [
HasTextInput,
ValidatesInput
Expand Down
10 changes: 10 additions & 0 deletions src/UiTextbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
class="ui-textbox-input" :type="type" :placeholder="placeholder" :name="name"
:id="id" :number="type === 'number' ? true : null" :min="minValue"
:max="maxValue" :step="stepValue" :autocomplete="autocomplete"
v-autofocus="autofocus"

@focus="focussed" @blur="blurred" @change="changed" @keydown="keydown"
@keydown.enter="keydownEnter" debounce="debounce"
Expand Down Expand Up @@ -60,6 +61,7 @@
<script>
import UiIcon from './UiIcon.vue';
import autofocus from '../directives/autofocus';
import HasTextInput from './mixins/HasTextInput';
import ValidatesInput from './mixins/ValidatesInput';
Expand Down Expand Up @@ -92,6 +94,10 @@ export default {
type: String,
default: 'off'
},
autofocus: {
type: Boolean,
default: false
},
min: Number,
max: Number,
step: {
Expand Down Expand Up @@ -240,6 +246,10 @@ export default {
UiIcon
},
directives: {
autofocus
},
mixins: [
HasTextInput,
ValidatesInput
Expand Down
3 changes: 3 additions & 0 deletions src/directives/autofocus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function(value) {
this.el.autofocus = Boolean(value);
}

0 comments on commit 85125a2

Please sign in to comment.