Skip to content

fix(AddMatchChoiceDialog): IME candidate Enter closes the dialog on macOS - #2396

Open
Isaries wants to merge 1 commit into
WISE-Community:developfrom
Isaries:fix/match-choice-ime-enter-closes-dialog
Open

Isaries wants to merge 1 commit into
WISE-Community:developfrom
Isaries:fix/match-choice-ime-enter-closes-dialog

Conversation

@Isaries

@Isaries Isaries commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

In a Match component that lets students add their own items, the Enter key that confirms an input method editor candidate (Chinese, Japanese, Korean) closes the "Enter Item Text" dialog. The input binds keydown.enter straight to save(), and in Chrome on macOS and in Safari that Enter arrives as a keydown with key Enter: Chrome sets isComposing, and Safari fires it after compositionend with key code 229.

What the student sees depends on the browser. In Chrome on macOS the form control only receives composed text on compositionend, so when earlier text is already in the field the dialog closes and saves it without the word being confirmed; when the field is still empty, nothing happens. In Safari the candidate is included, but the dialog closes on the first confirmation, so an item the student is still typing is saved unfinished.

Changes

  • Enter is handled in a new enterPressed() method that ignores the key while a composition is in progress, without calling preventDefault, so the IME can still commit the text.
  • A plain Enter calls preventDefault before saving, so the form's implicit submission does not save a second time.

Test

  • New add-match-choice-dialog.spec.ts: an Enter keydown with isComposing and one with key code 229 do not close the dialog and are not cancelled; a plain Enter closes it once with the text and is cancelled. Against the current develop, the composing cases fail with Expected spy MatDialogRef.close not to have been called. and the plain Enter case with Expected false to be true.

…acOS

The item text input binds keydown.enter directly to save(). Angular
matches that binding on event.key, and in Chrome on macOS and in Safari
the Enter that confirms an input method editor candidate (Chinese,
Japanese, Korean) arrives as a keydown with key "Enter": Chrome sets
isComposing, and Safari fires it after compositionend with keyCode 229.

The visible result differs by browser. In Chrome on macOS the form
control only receives composed text on compositionend, so when earlier
text is already in the field the dialog closes and saves that text
without the candidate being confirmed; when the field is still empty,
save() does nothing. In Safari the candidate is included, but the dialog
closes on the first confirmation, so an entry the student is still
typing is saved unfinished.

Handle Enter in a new enterPressed() method that ignores the key while a
composition is in progress, without calling preventDefault so the IME
can still commit the text. A plain Enter calls preventDefault before
saving, so the form's implicit submission does not save a second time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant