UNPKG

3.37 kBSource Map (JSON)View Raw
1{"version":3,"file":"primeng-focustrap.js","sources":["../../src/app/components/focustrap/focustrap.ts","../../src/app/components/focustrap/primeng-focustrap.ts"],"sourcesContent":["import {NgModule,Directive,ElementRef,HostListener, Input} from '@angular/core';\nimport {CommonModule} from '@angular/common';\nimport {DomHandler} from 'primeng/dom';\n\n@Directive({\n selector: '[pFocusTrap]',\n})\nexport class FocusTrap {\n\n @Input() pFocusTrapDisabled: boolean;\n\n constructor(public el: ElementRef) {}\n\n @HostListener('keydown.tab', ['$event'])\n @HostListener('keydown.shift.tab', ['$event'])\n onkeydown(e) {\n if (this.pFocusTrapDisabled !== true) {\n e.preventDefault();\n let focusableElements = DomHandler.getFocusableElements(this.el.nativeElement);\n if (focusableElements && focusableElements.length > 0) {\n if (!focusableElements[0].ownerDocument.activeElement) {\n focusableElements[0].focus();\n }\n else {\n let focusedIndex = focusableElements.indexOf(focusableElements[0].ownerDocument.activeElement);\n\n if (e.shiftKey) {\n if (focusedIndex == -1 || focusedIndex === 0)\n focusableElements[focusableElements.length - 1].focus();\n else\n focusableElements[focusedIndex - 1].focus();\n }\n else {\n if (focusedIndex == -1 || focusedIndex === (focusableElements.length - 1))\n focusableElements[0].focus();\n else\n focusableElements[focusedIndex + 1].focus();\n }\n }\n }\n }\n }\n}\n\n@NgModule({\n imports: [CommonModule],\n exports: [FocusTrap],\n declarations: [FocusTrap]\n})\nexport class FocusTrapModule { }\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;MAOa,SAAS;IAIlB,YAAmB,EAAc;QAAd,OAAE,GAAF,EAAE,CAAY;KAAI;IAIrC,SAAS,CAAC,CAAC;QACP,IAAI,IAAI,CAAC,kBAAkB,KAAK,IAAI,EAAE;YAClC,CAAC,CAAC,cAAc,EAAE,CAAC;YACnB,IAAI,iBAAiB,GAAG,UAAU,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,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