mirror of
https://github.com/flarum/framework.git
synced 2025-05-21 06:12:34 +08:00
37 lines
845 B
JavaScript
37 lines
845 B
JavaScript
import Ember from 'ember';
|
|
|
|
/**
|
|
A basic search input. Comes with the ability to be cleared by pressing
|
|
escape or with a button. Sends an action when enter is pressed.
|
|
*/
|
|
export default Ember.Component.extend({
|
|
layoutName: 'components/ui/search-input',
|
|
classNames: ['search-input'],
|
|
classNameBindings: ['active', 'value:clearable'],
|
|
|
|
didInsertElement: function() {
|
|
this.$('input').on('keydown', 'esc', function(e) {
|
|
self.clear();
|
|
});
|
|
|
|
var self = this;
|
|
this.$('.clear').on('mousedown click', function(e) {
|
|
e.preventDefault();
|
|
}).on('click', function(e) {
|
|
self.clear();
|
|
});
|
|
},
|
|
|
|
clear: function() {
|
|
this.set('value', '');
|
|
this.send('search');
|
|
this.$().find('input').focus();
|
|
},
|
|
|
|
actions: {
|
|
search: function() {
|
|
this.get('action')(this.get('value'));
|
|
}
|
|
}
|
|
});
|