UtilUpdated in v16Optional

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.

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;
  }
}

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

NameDescriptionTypeDefault
wrIsComposing(event)True while an input method is composing.(e: KeyboardEvent) => boolean—

See also