Usage
import { isPrintableKey } from 'ngwr/utils';
// Type-to-search: only consume printable keys, ignore arrows/Enter/etc.
@HostListener('keydown', ['$event']) onKey(e: KeyboardEvent) {
if (isPrintableKey(e)) buffer.push(e.key);
}Why ngwr provides this
The seemingly-obvious e.key.length === 1 is wrong: it matches modifier chords too (Ctrl+A has e.key === 'a', length 1). For type-to-search and inline-edit flows you want printable AND un-chorded — the predicate gets it right in one place.
// Native — "length === 1" looks right but matches modifier chords.
if (e.key.length === 1) buffer.push(e.key);
// → Ctrl+A: e.key is 'a' (length 1), so this pushes 'a'. Bug.
// ngwr — excludes chorded keys explicitly.
if (isPrintableKey(e)) buffer.push(e.key);API
| Name | Description | Type | Default |
|---|---|---|---|
isPrintableKey(event) | True when the key is a single printable character with no modifiers. Use for type-to-search and inline-edit flows. | (e: KeyboardEvent) => boolean | — |