Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

45 lines
1.1 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { AfterViewInit, Directive, ElementRef, Input } from '@angular/core';
import { Types } from '@app/framework/internal';
@Directive({
selector: '[sqxFocusOnInit]',
})
export class FocusOnInitDirective implements AfterViewInit {
@Input()
public select: boolean;
@Input('sqxFocusOnInit')
public enabled?: string | boolean | null = true;
constructor(
private readonly element: ElementRef<HTMLElement>,
) {
}
public ngAfterViewInit() {
if (this.enabled === false) {
return;
}
setTimeout(() => {
if (Types.isFunction(this.element.nativeElement.focus)) {
this.element.nativeElement.focus();
}
if (this.select) {
const input = this.element.nativeElement as HTMLInputElement;
if (Types.isFunction(input.select)) {
input.select();
}
}
}, 100);
}
}