1
0
mirror of https://github.com/flarum/core.git synced 2025-07-29 20:50:28 +02:00

Fix buggy autocomplete keyboard navigation when mouse is over popup

This commit is contained in:
Toby Zerner
2015-05-18 12:22:53 +09:30
parent 8c41195223
commit 547631ac93

View File

@@ -6,6 +6,7 @@ export default class AutocompleteDropdown extends Component {
this.active = m.prop(false); this.active = m.prop(false);
this.index = m.prop(0); this.index = m.prop(0);
this.keyWasJustPressed = false;
} }
view() { view() {
@@ -29,13 +30,11 @@ export default class AutocompleteDropdown extends Component {
if (!this.active()) return; if (!this.active()) return;
switch (e.which) { switch (e.which) {
case 40: // Down case 40: case 38: // Down/Up
this.setIndex(this.index() + 1, true); this.keyWasJustPressed = true;
e.preventDefault(); this.setIndex(this.index() + (e.which === 40 ? 1 : -1), true);
break; clearTimeout(this.keyWasJustPressedTimeout);
this.keyWasJustPressedTimeout = setTimeout(() => this.keyWasJustPressed = false, 500);
case 38: // Up
this.setIndex(this.index() - 1, true);
e.preventDefault(); e.preventDefault();
break; break;
@@ -53,6 +52,8 @@ export default class AutocompleteDropdown extends Component {
} }
setIndex(index, scrollToItem) { setIndex(index, scrollToItem) {
if (this.keyWasJustPressed && !scrollToItem) return;
var $dropdown = this.$(); var $dropdown = this.$();
var $items = $dropdown.find('li'); var $items = $dropdown.find('li');