adopted-ember-addons / adopted-ember-addons/ember-keyboard

Keyboard handler is triggered multiple times.

Ouverte
#699 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
bug
Langage dominant
JavaScript
Étoiles
177
Forks
59
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

Due to the fact that both key and code are checked when determining if a key is triggered, a keyboard handler could be called multiple times.

The following function will be called twice when pressing `NumpadEnter`
```js
@onKey('Enter')
@onKey('NumpadEnter')
onEnterOrNumpadEnterDown(e) {
this.args.onTrigger(e);
}
```

The reason for this behavior is the fact that in this scenario `event.code` is equal to `NumpadEnter` but `event.key` is equal to `Enter` Therefore when iterating over all keyboard handlers `@onKey('Enter')` will also be called since `event.key` will match. I found an older pull request #135 in which the option is discussed the specify a mode, this would enable developers to explicitly specify state if the they want to match based on key or code. Having this option would solve the problem at hand, but I understand that this proposal didn't make it in the final API design. But would it be possible to combine `@onKey('Enter')` and `@onKey('NumpadEnter')`? Let me know if I could help in any way.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.