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) [![Build Status](https://travis-ci.org/primefaces/primeng.

77 lines (73 loc) 3 kB
import { ElementRef, Input, HostListener, Directive, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { DomHandler } from 'primeng/dom'; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var FocusTrap = /** @class */ (function () { function FocusTrap(el) { this.el = el; } FocusTrap.prototype.onkeydown = function (e) { if (this.pFocusTrapDisabled !== true) { e.preventDefault(); var focusableElements = DomHandler.getFocusableElements(this.el.nativeElement); if (focusableElements && focusableElements.length > 0) { if (!document.activeElement) { focusableElements[0].focus(); } else { var focusedIndex = focusableElements.indexOf(document.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.ctorParameters = function () { return [ { type: ElementRef } ]; }; __decorate([ Input() ], FocusTrap.prototype, "pFocusTrapDisabled", void 0); __decorate([ HostListener('keydown.tab', ['$event']), HostListener('keydown.shift.tab', ['$event']) ], FocusTrap.prototype, "onkeydown", null); FocusTrap = __decorate([ Directive({ selector: '[pFocusTrap]', }) ], FocusTrap); return FocusTrap; }()); var FocusTrapModule = /** @class */ (function () { function FocusTrapModule() { } FocusTrapModule = __decorate([ NgModule({ imports: [CommonModule], exports: [FocusTrap], declarations: [FocusTrap] }) ], FocusTrapModule); return FocusTrapModule; }()); /** * Generated bundle index. Do not edit. */ export { FocusTrap, FocusTrapModule }; //# sourceMappingURL=primeng-focustrap.js.map