mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-21 10:43:16 +00:00
* [deps]: Update eslint to v9 * resolve lint errors, upgrade eslint, replace unmaintained packages * refresh lockfile --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Brandon <btreston@bitwarden.com> Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Co-authored-by: Thomas Rittson <trittson@bitwarden.com>
32 lines
758 B
TypeScript
32 lines
758 B
TypeScript
import { Directive, ElementRef, Input, NgZone } from "@angular/core";
|
|
import { take } from "rxjs";
|
|
|
|
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());
|
|
}
|
|
}
|
|
}
|
|
}
|