2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import {isBlank} from '@ember/utils';
|
2016-04-19 18:55:10 +03:00
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
actions: {
|
|
|
|
captureMouseDown(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
},
|
|
|
|
|
|
|
|
search(term) {
|
2017-10-03 08:00:25 +03:00
|
|
|
// open dropdown if not open and term is present
|
|
|
|
// close dropdown if open and term is blank
|
2016-04-19 18:55:10 +03:00
|
|
|
if (isBlank(term) === this.get('select.isOpen')) {
|
2017-10-03 08:00:25 +03:00
|
|
|
isBlank(term) ? this.close() : this.open();
|
|
|
|
|
|
|
|
// ensure focus isn't lost when dropdown is closed
|
|
|
|
if (isBlank(term)) {
|
|
|
|
this._focusInput();
|
|
|
|
}
|
2016-04-19 18:55:10 +03:00
|
|
|
}
|
|
|
|
|
2017-10-03 08:00:25 +03:00
|
|
|
this.get('select').actions.search(term);
|
2016-04-19 18:55:10 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
focusInput() {
|
2017-10-03 08:00:25 +03:00
|
|
|
this._focusInput();
|
2016-04-19 18:55:10 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
resetInput() {
|
|
|
|
this.$('input').val('');
|
|
|
|
},
|
|
|
|
|
|
|
|
handleKeydown(e) {
|
|
|
|
let select = this.get('select');
|
2016-09-14 18:11:41 +03:00
|
|
|
|
|
|
|
// TODO: remove keycode check once EPS is updated to 1.0
|
|
|
|
if (!select.isOpen || e.keyCode === 32) {
|
2016-04-19 18:55:10 +03:00
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
}
|
2018-01-11 20:43:23 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
open() {
|
|
|
|
this.get('select.actions').open();
|
|
|
|
},
|
|
|
|
|
|
|
|
close() {
|
|
|
|
this.get('select.actions').close();
|
|
|
|
},
|
|
|
|
|
|
|
|
_focusInput() {
|
|
|
|
this.$('input')[0].focus();
|
2016-04-19 18:55:10 +03:00
|
|
|
}
|
|
|
|
});
|