javascript-tutorial / javascript-tutorial/en.javascript.info

Keyboard events: keydown filtering example can't block IME-composed input (Korean/Japanese/Chinese)

Abierto Apto para principiantes
#3,978 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
HTML
Estrellas
25.5k
Forks
4k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

## Article

[Keyboard: keydown and keyup](https://javascript.info/keyboard-events) — the "Default actions" section, phone-number filter example:

```html

```

## 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:

- `keydown` fires with `event.key == "Process"` (and `keyCode` 229), not the actual character.
- More importantly, calling `preventDefault()` / returning `false` on that `keydown` does **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, the `input` event 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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

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.

Evaluación

Stack tecnológico
html, javascript
Área
documentation
Tipo de issue
Documentación
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
76/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.