UtilOptional

trapFocus

Keeps Tab and Shift+Tab cycling inside a container, such as a dialog.

Usage

import { trapFocus } from 'ngwr/utils';

@HostListener('keydown', ['$event']) onKey(e: KeyboardEvent) {
  trapFocus(dialogRef.nativeElement, e);
}

API

NameDescriptionTypeDefault
trapFocus(root, event)Cycles Tab focus inside root. Call it from a keydown handler; returns true when it handled a Tab.(root: HTMLElement, e: KeyboardEvent) => boolean—

See also