UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primeng.svg)](https://badge.fury.io/js/primeng) [![Discord](https://img.shields.io/discord/557940238991753

64 lines (60 loc) 2.23 kB
import { Directive, ElementRef, Input, HostListener, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { DomHandler } from 'primeng/dom'; class FocusTrap { constructor(el) { this.el = el; } onkeydown(e) { if (this.pFocusTrapDisabled !== true) { e.preventDefault(); let focusableElements = DomHandler.getFocusableElements(this.el.nativeElement); if (focusableElements && focusableElements.length > 0) { if (!focusableElements[0].ownerDocument.activeElement) { focusableElements[0].focus(); } else { let focusedIndex = focusableElements.indexOf(focusableElements[0].ownerDocument.activeElement); if (e.shiftKey) { if (focusedIndex == -1 || focusedIndex === 0) focusableElements[focusableElements.length - 1].focus(); else focusableElements[focusedIndex - 1].focus(); } else { if (focusedIndex == -1 || focusedIndex === (focusableElements.length - 1)) focusableElements[0].focus(); else focusableElements[focusedIndex + 1].focus(); } } } } } } FocusTrap.decorators = [ { type: Directive, args: [{ selector: '[pFocusTrap]', },] } ]; FocusTrap.ctorParameters = () => [ { type: ElementRef } ]; FocusTrap.propDecorators = { pFocusTrapDisabled: [{ type: Input }], onkeydown: [{ type: HostListener, args: ['keydown.tab', ['$event'],] }, { type: HostListener, args: ['keydown.shift.tab', ['$event'],] }] }; class FocusTrapModule { } FocusTrapModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule], exports: [FocusTrap], declarations: [FocusTrap] },] } ]; /** * Generated bundle index. Do not edit. */ export { FocusTrap, FocusTrapModule }; //# sourceMappingURL=primeng-focustrap.js.map