mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 04:23:04 +00:00
22 lines
529 B
TypeScript
22 lines
529 B
TypeScript
import { Directive, AfterViewInit, ElementRef, Input } from '@angular/core';
|
|
import { isNotEmpty } from '../empty.util';
|
|
|
|
@Directive({
|
|
selector: '[dsAutoFocus]'
|
|
})
|
|
export class AutoFocusDirective implements AfterViewInit {
|
|
|
|
@Input() autoFocusSelector: string;
|
|
|
|
constructor(private el: ElementRef) {
|
|
}
|
|
|
|
ngAfterViewInit() {
|
|
if (isNotEmpty(this.autoFocusSelector)) {
|
|
return this.el.nativeElement.querySelector(this.autoFocusSelector).focus();
|
|
} else {
|
|
return this.el.nativeElement.focus();
|
|
}
|
|
}
|
|
}
|