mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 22:02:11 +03:00
1543ffe6ed
closes https://github.com/TryGhost/Ghost/issues/9075 - ensure we re-focus the input element after closing the dropdown so that it's not necessary to click on the search input again after using backspace - removes unnecessary use of `run.scheduleOnce` - this was causing the error in TryGhost/Ghost#9075 because search was happening out of sync with the open/close of the dropdown in turn causing `ember-basic-dropdown` to try measuring non-existent elements - alternative fix would be to wrap each open/close, focus, and search call in separate `run.scheduleOnce('afterRender', ...)` calls - remove use of `invokeAction`, it's not been necessary in Ember for a while now and we should be calling methods directly where possible for easier debugging
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
import Component from '@ember/component';
|
|
import {isBlank} from '@ember/utils';
|
|
|
|
export default Component.extend({
|
|
open() {
|
|
this.get('select.actions').open();
|
|
},
|
|
|
|
close() {
|
|
this.get('select.actions').close();
|
|
},
|
|
|
|
_focusInput() {
|
|
this.$('input')[0].focus();
|
|
},
|
|
|
|
actions: {
|
|
captureMouseDown(e) {
|
|
e.stopPropagation();
|
|
},
|
|
|
|
search(term) {
|
|
// open dropdown if not open and term is present
|
|
// close dropdown if open and term is blank
|
|
if (isBlank(term) === this.get('select.isOpen')) {
|
|
isBlank(term) ? this.close() : this.open();
|
|
|
|
// ensure focus isn't lost when dropdown is closed
|
|
if (isBlank(term)) {
|
|
this._focusInput();
|
|
}
|
|
}
|
|
|
|
this.get('select').actions.search(term);
|
|
},
|
|
|
|
focusInput() {
|
|
this._focusInput();
|
|
},
|
|
|
|
resetInput() {
|
|
this.$('input').val('');
|
|
},
|
|
|
|
handleKeydown(e) {
|
|
let select = this.get('select');
|
|
|
|
// TODO: remove keycode check once EPS is updated to 1.0
|
|
if (!select.isOpen || e.keyCode === 32) {
|
|
e.stopPropagation();
|
|
}
|
|
}
|
|
}
|
|
});
|