Keyboard events: keydown filtering example can't block IME-composed input (Korean/Japanese/Chinese)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 76/100
- Tipo de issue
- Documentación
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Stack tecnológico
- html, javascript
- Área
- documentation
Línea de trabajo
Abre el artículo Keyboard: keydown y keyup y revisa la sección Default actions, especialmente el ejemplo del filtro de números de teléfono y la explicación del input event en la introducción. Añade una nota breve que explique la limitación de IME y por qué input es preferible para hacer un seguimiento del texto insertado o validarlo; después, verifica la redacción con el ejemplo.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- HTML
- Estrellas
- 25.5k
- Forks
- 4k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de javascript-tutorial/en.javascript.info
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Todos los issues de javascript-tutorial/en.javascript.info
Issues similares
-
documentation help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
-
user-reported
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Kong/developer.konghq.com#7316 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
HarperFast/skills#96 ·
-
Client support matrix inclusion Abiertoenhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
infinispan/infinispan#18150 ·