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