Icard/angular-clarity-master(work.../node_modules/primeng/esm2022/autofocus/autofocus.mjs

71 lines
7.6 KiB
JavaScript

import { CommonModule } from '@angular/common';
import { Directive, Input, NgModule, booleanAttribute } from '@angular/core';
import { DomHandler } from 'primeng/dom';
import * as i0 from "@angular/core";
/**
* AutoFocus manages focus on focusable element on load.
* @group Components
*/
export class AutoFocus {
host;
constructor(host) {
this.host = host;
}
/**
* When present, it specifies that the component should automatically get focus on load.
* @group Props
*/
autofocus = false;
focused = false;
ngAfterContentChecked() {
// This sets the `attr.autofocus` which is different than the Input `autofocus` attribute.
if (this.autofocus === false) {
this.host.nativeElement.removeAttribute('autofocus');
}
else {
this.host.nativeElement.setAttribute('autofocus', true);
}
if (!this.focused) {
if (this.autofocus) {
setTimeout(() => {
const focusableElements = DomHandler.getFocusableElements(this.host.nativeElement);
if (focusableElements.length === 0) {
this.host.nativeElement.focus();
}
if (focusableElements.length > 0) {
focusableElements[0].focus();
}
this.focused = true;
});
}
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: AutoFocus, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "17.3.7", type: AutoFocus, selector: "[pAutoFocus]", inputs: { autofocus: ["autofocus", "autofocus", booleanAttribute] }, host: { classAttribute: "p-element" }, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: AutoFocus, decorators: [{
type: Directive,
args: [{
selector: '[pAutoFocus]',
host: {
class: 'p-element'
}
}]
}], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { autofocus: [{
type: Input,
args: [{ transform: booleanAttribute }]
}] } });
export class AutoFocusModule {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: AutoFocusModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.7", ngImport: i0, type: AutoFocusModule, declarations: [AutoFocus], imports: [CommonModule], exports: [AutoFocus] });
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: AutoFocusModule, imports: [CommonModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: AutoFocusModule, decorators: [{
type: NgModule,
args: [{
imports: [CommonModule],
exports: [AutoFocus],
declarations: [AutoFocus]
}]
}] });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXV0b2ZvY3VzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2FwcC9jb21wb25lbnRzL2F1dG9mb2N1cy9hdXRvZm9jdXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBQy9DLE9BQU8sRUFBRSxTQUFTLEVBQWMsS0FBSyxFQUFFLFFBQVEsRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLGVBQWUsQ0FBQztBQUN6RixPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sYUFBYSxDQUFDOztBQUN6Qzs7O0dBR0c7QUFPSCxNQUFNLE9BQU8sU0FBUztJQUNFO0lBQXBCLFlBQW9CLElBQWdCO1FBQWhCLFNBQUksR0FBSixJQUFJLENBQVk7SUFBRyxDQUFDO0lBQ3hDOzs7T0FHRztJQUNxQyxTQUFTLEdBQVksS0FBSyxDQUFDO0lBRW5FLE9BQU8sR0FBWSxLQUFLLENBQUM7SUFFekIscUJBQXFCO1FBQ2pCLDBGQUEwRjtRQUMxRixJQUFJLElBQUksQ0FBQyxTQUFTLEtBQUssS0FBSyxFQUFFO1lBQzFCLElBQUksQ0FBQyxJQU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udHMubGVuZ3RoID4gMCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgZm9jdXNhYmxlRWxlbWVudHNbMF0uZm9jdXMoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZm9jdXNlZCA9IHRydWU7XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59XG5cbkBOZ01vZHVsZSh7XG4gICAgaW1wb3J0czogW0NvbW1vbk1vZHVsZV0sXG4gICAgZXhwb3J0czogW0F1dG9Gb2N1c10sXG4gICAgZGVjbGFyYXRpb25zOiBbQXV0b0ZvY3VzXVxufSlcbmV4cG9ydCBjbGFzcyBBdXRvRm9jdXNNb2R1bGUge31cbiJdfQ==