Replace event.keyCode with event.key equivalents.

This commit is contained in:
Aaron van Geffen 2021-02-16 15:24:42 +01:00
parent 4402521051
commit 70e6001c85

View File

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