Skip to content

Commit

Permalink
refactor(abc:auto-focus): bump signal (#1859)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk authored Jan 18, 2025
1 parent 3212941 commit 29b7dad
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/abc/auto-focus/auto-focus.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
DestroyRef,
Directive,
ElementRef,
Input,
booleanAttribute,
inject,
input,
numberAttribute
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { timer } from 'rxjs';
import { take, timer } from 'rxjs';

@Directive({
selector: '[auto-focus], input[autofocus="autofocus"], textarea[autofocus="autofocus"]',
Expand All @@ -21,16 +21,16 @@ export class AutoFocusDirective implements AfterViewInit {
private readonly platform = inject(Platform);
private readonly destroy$ = inject(DestroyRef);

@Input({ transform: booleanAttribute }) enabled = true;
@Input({ transform: numberAttribute }) delay = 300;
enabled = input<boolean, boolean | string | null | undefined>(true, { transform: booleanAttribute });
delay = input<number, number | string | null | undefined>(300, { transform: numberAttribute });

ngAfterViewInit(): void {
const el = this.el;
if (!this.platform.isBrowser || !(el instanceof HTMLElement) || !this.enabled) {
if (!this.platform.isBrowser || !(el instanceof HTMLElement) || !this.enabled()) {
return;
}
timer(this.delay)
.pipe(takeUntilDestroyed(this.destroy$))
timer(this.delay())
.pipe(takeUntilDestroyed(this.destroy$), take(1))
.subscribe(() => el.focus({ preventScroll: false }));
}
}

0 comments on commit 29b7dad

Please sign in to comment.