mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
* [deps] Autofill: Update prettier to v3 * prettier formatting updates --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Jonathan Prusik <jprusik@classynemesis.com>
31 lines
755 B
TypeScript
31 lines
755 B
TypeScript
import { Directive, ElementRef, Input, NgZone } from "@angular/core";
|
|
import { take } from "rxjs/operators";
|
|
|
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
|
|
|
@Directive({
|
|
selector: "[appAutofocus]",
|
|
})
|
|
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());
|
|
}
|
|
}
|
|
}
|
|
}
|