mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-05 23:53:21 +00:00
* angular 18 upgrade * wip * wip * remove @types/glob, fix jest version, use standalone: false * clean up * npm ci
32 lines
768 B
TypeScript
32 lines
768 B
TypeScript
import { Directive, ElementRef, Input, NgZone } from "@angular/core";
|
|
import { take } from "rxjs/operators";
|
|
|
|
import { Utils } from "@/jslib/common/src/misc/utils";
|
|
|
|
@Directive({
|
|
selector: "[appAutofocus]",
|
|
standalone: false,
|
|
})
|
|
export class AutofocusDirective {
|
|
@Input() set appAutofocus(condition: boolean | string) {
|
|
this.autofocus = condition === "" || condition === true;
|
|
}
|
|
|
|
private autofocus: boolean;
|
|
|
|
constructor(
|
|
private el: ElementRef,
|
|
private ngZone: NgZone,
|
|
) {}
|
|
|
|
ngOnInit() {
|
|
if (!Utils.isMobileBrowser && this.autofocus) {
|
|
if (this.ngZone.isStable) {
|
|
this.el.nativeElement.focus();
|
|
} else {
|
|
this.ngZone.onStable.pipe(take(1)).subscribe(() => this.el.nativeElement.focus());
|
|
}
|
|
}
|
|
}
|
|
}
|