mirror of https://github.com/Squidex/squidex.git
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.
46 lines
1.0 KiB
46 lines
1.0 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 = 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: HTMLInputElement = <any>this.element.nativeElement;
|
|
|
|
if (Types.isFunction(input.select)) {
|
|
input.select();
|
|
}
|
|
}
|
|
}, 100);
|
|
}
|
|
}
|