UX: Autofocus when input is empty.

This commit is contained in:
Guo Xiang Tan 2015-09-13 09:41:05 +08:00
parent 2ae0ef0ad9
commit c1deee772b
3 changed files with 11 additions and 2 deletions

View File

@ -9,5 +9,9 @@ export default TextField.extend({
focusIn: function() { focusIn: function() {
Em.run.later(() => { this.$().select(); }); Em.run.later(() => { this.$().select(); });
} },
becomeFocused: function() {
if (this.get('hasAutofocus')) this.$().focus();
}.on('didInsertElement')
}); });

View File

@ -13,6 +13,11 @@ export default Ember.Controller.extend({
context_id: null, context_id: null,
context: null, context: null,
@computed('q')
hasAutofocus(q) {
return Em.isEmpty(q);
},
@computed('skip_context', 'context') @computed('skip_context', 'context')
searchContextEnabled: { searchContextEnabled: {
get(skip,context){ get(skip,context){

View File

@ -1,5 +1,5 @@
<div class="search row clearfix"> <div class="search row clearfix">
{{search-text-field value=searchTerm class="input-xxlarge search no-blur" action="search"}} {{search-text-field value=searchTerm class="input-xxlarge search no-blur" action="search" hasAutofocus=hasAutofocus}}
{{d-button action="search" icon="search" class="btn-primary" disabled=isNotValidSearchTerm}} {{d-button action="search" icon="search" class="btn-primary" disabled=isNotValidSearchTerm}}
{{#if canBulkSelect}} {{#if canBulkSelect}}
{{#if model.posts}} {{#if model.posts}}