Skip to content

Commit

Permalink
triggerKeyEvent now uses find instead of filter[0]
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Dec 12, 2020
1 parent a1ed85e commit 951eda7
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Target from './-target';
import { log } from '@ember/test-helpers/dom/-logging';
import isFormControl from './-is-form-control';
import { runHooks, registerHook } from '../-internal/helper-hooks';
import { find } from '../ie-11-polyfills';

registerHook(
'triggerKeyEvent',
Expand Down Expand Up @@ -117,10 +118,10 @@ function keyFromKeyCodeAndModifiers(keycode: number, modifiers: KeyModifiers): s
*/
function keyCodeFromKey(key: string) {
let keys = Object.keys(keyFromKeyCode);
let keyCode = keys.filter(keyCode => keyFromKeyCode[Number(keyCode)] === key)[0];
if (!keyCode) {
keyCode = keys.filter(keyCode => keyFromKeyCode[Number(keyCode)] === key.toLowerCase())[0];
}
let keyCode =
find(keys, (keyCode: string) => keyFromKeyCode[Number(keyCode)] === key) ||
find(keys, (keyCode: string) => keyFromKeyCode[Number(keyCode)] === key.toLowerCase());

return keyCode !== undefined ? parseInt(keyCode) : undefined;
}

Expand Down

0 comments on commit 951eda7

Please sign in to comment.