import { wrIsComposing } from 'ngwr/utils';
onKeydown(event: KeyboardEvent): void {
if (wrIsComposing(event)) return;
switch (event.key) {
case 'Enter': this.commit(); break;
case 'Escape': this.close(); break;
}
}wrIsComposing
True while an input method (IME) is composing, so the key belongs to it and not to your handler.
Usage
Return early on it in every keydown handler that reads Enter, Escape or the arrows over a text field.
Knowing the state between events
It is for keydown only; in an input or blur handler, track compositionstart and compositionend instead.
@Component({
host: {
'(compositionstart)': 'composing = true',
'(compositionend)': 'composing = false; onSettledInput()',
'(input)': 'composing ? null : onSettledInput()',
},
})API
| Name | Description | Type | Default |
|---|---|---|---|
wrIsComposing(event) | True while an input method is composing. | (e: KeyboardEvent) => boolean | — |
See also
Guide KeyboardBind shortcuts, show them as keycaps, and see which keys each component handles.Util wrHasModifierTrue when Ctrl, Cmd, Alt, Shift or Meta is held during a KeyboardEvent.Util wrIsPrintableKeyTrue for a single printable character typed without Ctrl, Cmd or Alt (Shift is allowed).Util WR_KEYSKeyboardEvent.key constants, the WrKey union of their values, and WR_KEY_LABELS, what each key is called on a keycap.