UNPKG

primeng

Version:

PrimeNG is an open source UI library for Angular featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeB

1 lines 4.5 kB
{"version":3,"file":"primeng-autofocus.mjs","sources":["../../src/autofocus/autofocus.ts","../../src/autofocus/primeng-autofocus.ts"],"sourcesContent":["import { DOCUMENT, isPlatformBrowser } from '@angular/common';\nimport { booleanAttribute, Directive, ElementRef, inject, Input, NgModule, PLATFORM_ID } from '@angular/core';\nimport { BaseComponent } from 'primeng/basecomponent';\nimport { DomHandler } from 'primeng/dom';\n\n/**\n * AutoFocus manages focus on focusable element on load.\n * @group Components\n */\n@Directive({\n selector: '[pAutoFocus]',\n standalone: true\n})\nexport class AutoFocus extends BaseComponent {\n /**\n * When present, it specifies that the component should automatically get focus on load.\n * @deprecated use [pAutoFocus]=\"true\"\n * @group Props\n */\n @Input({ transform: booleanAttribute }) autofocus: boolean = false;\n /**\n * When present, it specifies that the component should automatically get focus on load.\n * @group Props\n */\n @Input('pAutoFocus') _autofocus: boolean = false;\n\n focused: boolean = false;\n\n platformId = inject(PLATFORM_ID);\n\n document: Document = inject(DOCUMENT);\n\n host: ElementRef = inject(ElementRef);\n\n ngAfterContentChecked() {\n // This sets the `attr.autofocus` which is different than the Input `autofocus` attribute.\n if (this.autofocus === false) {\n this.host.nativeElement.removeAttribute('autofocus');\n } else {\n this.host.nativeElement.setAttribute('autofocus', true);\n }\n\n if (!this.focused) {\n this.autoFocus();\n }\n }\n\n ngAfterViewChecked() {\n if (!this.focused) {\n this.autoFocus();\n }\n }\n\n autoFocus() {\n if (isPlatformBrowser(this.platformId) && this._autofocus) {\n setTimeout(() => {\n const focusableElements = DomHandler.getFocusableElements(this.host?.nativeElement);\n\n if (focusableElements.length === 0) {\n this.host.nativeElement.focus();\n }\n if (focusableElements.length > 0) {\n focusableElements[0].focus();\n }\n\n this.focused = true;\n });\n }\n }\n}\n\n@NgModule({\n imports: [AutoFocus],\n exports: [AutoFocus]\n})\nexport class AutoFocusModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;AAKA;;;AAGG;AAKG,MAAO,SAAU,SAAQ,aAAa,CAAA;AACxC;;;;AAIG;IACqC,SAAS,GAAY,KAAK;AAClE;;;AAGG;IACkB,UAAU,GAAY,KAAK;IAEhD,OAAO,GAAY,KAAK;AAExB,IAAA,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC;AAEhC,IAAA,QAAQ,GAAa,MAAM,CAAC,QAAQ,CAAC;AAErC,IAAA,IAAI,GAAe,MAAM,CAAC,UAAU,CAAC;IAErC,qBAAqB,GAAA;;AAEjB,QAAA,IAAI,IAAI,CAAC,SAAS,KAAK,KAAK,EAAE;YAC1B,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,WAAW,CAAC;;aACjD;YACH,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC;;AAG3D,QAAA,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACf,IAAI,CAAC,SAAS,EAAE;;;IAIxB,kBAAkB,GAAA;AACd,QAAA,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACf,IAAI,CAAC,SAAS,EAAE;;;IAIxB,SAAS,GAAA;QACL,IAAI,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE;YACvD,UAAU,CAAC,MAAK;AACZ,gBAAA,MAAM,iBAAiB,GAAG,UAAU,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC;AAEnF,gBAAA,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE;AAChC,oBAAA,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE;;AAEnC,gBAAA,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE;AAC9B,oBAAA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