primeng
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primeng) [ • 2.74 kB
JavaScript
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;
};
let FocusTrap = 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 (!document.activeElement) {
focusableElements[0].focus();
}
else {
let 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 = () => [
{ 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);
let FocusTrapModule = class FocusTrapModule {
};
FocusTrapModule = __decorate([
NgModule({
imports: [CommonModule],
exports: [FocusTrap],
declarations: [FocusTrap]
})
], FocusTrapModule);
/**
* Generated bundle index. Do not edit.
*/
export { FocusTrap, FocusTrapModule };
//# sourceMappingURL=primeng-focustrap.js.map