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:
@@ -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');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user