[59329aa] | 1 | import * as i0 from '@angular/core';
|
---|
| 2 | import { Directive, Input, HostListener, NgModule } from '@angular/core';
|
---|
| 3 | import { CommonModule } from '@angular/common';
|
---|
| 4 | import { DomHandler } from 'primeng/dom';
|
---|
| 5 |
|
---|
| 6 | class FocusTrap {
|
---|
| 7 | constructor(el) {
|
---|
| 8 | this.el = el;
|
---|
| 9 | }
|
---|
| 10 | onkeydown(e) {
|
---|
| 11 | if (this.pFocusTrapDisabled !== true) {
|
---|
| 12 | e.preventDefault();
|
---|
| 13 | let focusableElements = DomHandler.getFocusableElements(this.el.nativeElement);
|
---|
| 14 | if (focusableElements && focusableElements.length > 0) {
|
---|
| 15 | if (!focusableElements[0].ownerDocument.activeElement) {
|
---|
| 16 | focusableElements[0].focus();
|
---|
| 17 | }
|
---|
| 18 | else {
|
---|
| 19 | let focusedIndex = focusableElements.indexOf(focusableElements[0].ownerDocument.activeElement);
|
---|
| 20 | if (e.shiftKey) {
|
---|
| 21 | if (focusedIndex == -1 || focusedIndex === 0)
|
---|
| 22 | focusableElements[focusableElements.length - 1].focus();
|
---|
| 23 | else
|
---|
| 24 | focusableElements[focusedIndex - 1].focus();
|
---|
| 25 | }
|
---|
| 26 | else {
|
---|
| 27 | if (focusedIndex == -1 || focusedIndex === (focusableElements.length - 1))
|
---|
| 28 | focusableElements[0].focus();
|
---|
| 29 | else
|
---|
| 30 | focusableElements[focusedIndex + 1].focus();
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 | FocusTrap.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: FocusTrap, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
|
---|
| 38 | FocusTrap.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.0.0", type: FocusTrap, selector: "[pFocusTrap]", inputs: { pFocusTrapDisabled: "pFocusTrapDisabled" }, host: { listeners: { "keydown.tab": "onkeydown($event)", "keydown.shift.tab": "onkeydown($event)" }, classAttribute: "p-element" }, ngImport: i0 });
|
---|
| 39 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: FocusTrap, decorators: [{
|
---|
| 40 | type: Directive,
|
---|
| 41 | args: [{
|
---|
| 42 | selector: '[pFocusTrap]',
|
---|
| 43 | host: {
|
---|
| 44 | 'class': 'p-element'
|
---|
| 45 | }
|
---|
| 46 | }]
|
---|
| 47 | }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { pFocusTrapDisabled: [{
|
---|
| 48 | type: Input
|
---|
| 49 | }], onkeydown: [{
|
---|
| 50 | type: HostListener,
|
---|
| 51 | args: ['keydown.tab', ['$event']]
|
---|
| 52 | }, {
|
---|
| 53 | type: HostListener,
|
---|
| 54 | args: ['keydown.shift.tab', ['$event']]
|
---|
| 55 | }] } });
|
---|
| 56 | class FocusTrapModule {
|
---|
| 57 | }
|
---|
| 58 | FocusTrapModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: FocusTrapModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
---|
| 59 | FocusTrapModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: FocusTrapModule, declarations: [FocusTrap], imports: [CommonModule], exports: [FocusTrap] });
|
---|
| 60 | FocusTrapModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: FocusTrapModule, imports: [[CommonModule]] });
|
---|
| 61 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: FocusTrapModule, decorators: [{
|
---|
| 62 | type: NgModule,
|
---|
| 63 | args: [{
|
---|
| 64 | imports: [CommonModule],
|
---|
| 65 | exports: [FocusTrap],
|
---|
| 66 | declarations: [FocusTrap]
|
---|
| 67 | }]
|
---|
| 68 | }] });
|
---|
| 69 |
|
---|
| 70 | /**
|
---|
| 71 | * Generated bundle index. Do not edit.
|
---|
| 72 | */
|
---|
| 73 |
|
---|
| 74 | export { FocusTrap, FocusTrapModule };
|
---|