Modernise autosuggest code #25

Merged
Roflin merged 3 commits from autosuggest into master 2021-05-17 20:19:07 +02:00
Showing only changes of commit 70e6001c85 - Show all commits

View File

@ -35,17 +35,17 @@ class AutoSuggest {
return;
}
switch (event.keyCode) {
case 13: // Enter
switch (event.key) {
case 'Enter':
event.preventDefault();
this.container.children[this.selectedIndex].click();
break;
case 38: // Arrow up
case 40: // Arrow down
case 'ArrowUp':
case 'ArrowDown':
event.preventDefault();
this.findSelectedElement().className = '';
this.selectedIndex += event.keyCode === 38 ? -1 : 1;
this.selectedIndex += event.key === 'ArrowUp' ? -1 : 1;
if (this.selectedIndex < 0) {
this.selectedIndex = this.container.children.length - 1;
} else if (this.selectedIndex === this.container.children.length) {
@ -61,7 +61,7 @@ class AutoSuggest {
};
onType(event) {
if (event.keyCode === 13 || event.keyCode === 38 || event.keyCode === 40) {
if (['Enter', 'ArrowDown', 'ArrowUp'].indexOf(event.key) !== -1) {
return;
}