Keyboard events: keydown filtering example can't block IME-composed input (Korean/Japanese/Chinese)
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 76/100
- Type d'issue
- Documentation
- Clarté
- Plutôt claire
- Activité
- Calme
- Stack technique
- html, javascript
- Domaine
- documentation
Piste de recherche
Ouvrez l’article Keyboard: keydown and keyup et relisez la section Default actions, en particulier l’exemple de filtre de numéro de téléphone et la présentation de l’input event dans l’introduction. Ajoutez une courte note expliquant la limitation de l’IME et pourquoi input est préférable pour suivre ou valider le texte inséré, puis vérifiez la formulation par rapport à l’exemple.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Article
Keyboard: keydown and keyup — the "Default actions" section, phone-number filter example:
<input onkeydown="return checkPhoneKey(event.key)" placeholder="Phone, please" type="tel">
Problem
The example (and the surrounding text) implies that returning false from keydown reliably prevents unwanted characters from being entered. That holds for direct (Latin) keyboard input, but not for languages typed through an IME (Input Method Editor), such as Korean, Japanese and Chinese.
With an IME active:
keydownfires withevent.key == "Process"(andkeyCode229), not the actual character.- More importantly, calling
preventDefault()/ returningfalseon thatkeydowndoes not cancel the text insertion, because the character is produced by the IME composition, not by the key's default action.
As a result, Korean/Japanese/Chinese characters pass straight through the filter and appear in the field. This was reported by a Korean reader of the Korean translation (ko.javascript.info), and is easy to reproduce by switching to a Korean IME and typing into the demo.
Suggestion
Add a short note after the example, along these lines:
Please note: this filter only works for direct keyboard input. Text composed via an IME (used for languages such as Korean, Japanese or Chinese) is inserted by the input method, not by the key's default action, so it can't be blocked in
keydown. That's one more reason why, for tracking or validating what actually gets into the field, theinputevent is a better choice.
This ties in nicely with the introduction of the article, which already recommends the input event for tracking input from any source.
Happy to send a PR if the note sounds good.
- Langage dominant
- HTML
- Étoiles
- 25.5k
- Forks
- 4k
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de javascript-tutorial/en.javascript.info
-
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
Toutes les issues de javascript-tutorial/en.javascript.info
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
agilepathway/label-checker#640 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
BasedHardware/omi#15662 · 1 commentaire ·
-
documentation help wanted
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100
-
Docs are out of date: README structure tree, "Make It Yours" pointer, CONTRIBUTING test notes Ouvertedocumentation good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
amponce/archive-movie-browser#167 ·
-
user-reported
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
Kong/developer.konghq.com#7316 ·