import { AfterViewInit, Directive, ElementRef, Input } from '@angular/core';

@Directive({
  selector: '[msfaAutofocus]',
})
export class AutofocusDirective implements AfterViewInit {
  @Input() msfaAutofocus: boolean;

  constructor(private elementRef: ElementRef) {}

  ngAfterViewInit(): void {
    if (this.msfaAutofocus) {
      (this.elementRef.nativeElement as HTMLElement).focus();
    }
  }
}
