Usage
import { hasModifier } from 'ngwr/utils';
@HostListener('keydown', ['$event']) onKey(e: KeyboardEvent) {
if (hasModifier(e)) return; // let Ctrl/Cmd-+key shortcuts through
if (e.key === 'k') focusSearch();
}Why ngwr provides this
Almost every single-key shortcut (J/K nav, slash-to-search, type-to-jump) needs to back off when a chord is being typed — otherwise Cmd+K hits both the OS shortcut AND your handler. Spelling out e.ctrlKey || e.metaKey || e.altKey || e.shiftKey everywhere is noise; the helper makes the intent obvious.
// Native — boilerplate, repeats across handlers.
@HostListener('keydown', ['$event']) onKey(e: KeyboardEvent) {
if (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey) return;
if (e.key === 'k') focusSearch();
}
// ngwr — one call, OS-agnostic.
@HostListener('keydown', ['$event']) onKey(e: KeyboardEvent) {
if (hasModifier(e)) return;
if (e.key === 'k') focusSearch();
}API
| Name | Description | Type | Default |
|---|---|---|---|
hasModifier(event) | True when Ctrl / Cmd / Alt / Shift / Meta is currently held. Use to bypass plain-key shortcuts during chorded shortcuts. | (e: KeyboardEvent) => boolean | — |