[Library | Trunk]: Input text move cursor to start on unfocus status,

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60823 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2021-04-09 13:01:07 +00:00
parent e9bf5d8503
commit 1619cb6f2b
1 changed files with 6 additions and 1 deletions

View File

@ -51,7 +51,7 @@ export interface Option {
<div [ngClass]="inputClass"
[class.uk-form-danger]="formControl.invalid && formControl.touched"
[attr.uk-tooltip]="formControl.disabled?'title: This field is not editable; pos: bottom-left':''">
<input class="uk-input" [placeholder]="placeholder" [formControl]="formControl">
<input #input class="uk-input" [placeholder]="placeholder" [formControl]="formControl">
</div>
</ng-template>
<ng-template [ngIf]="type === 'textarea'">
@ -176,6 +176,8 @@ export class InputComponent implements OnInit, OnDestroy, OnChanges {
@Input('formInput') formControl: AbstractControl;
@Input('type') type: 'text' | 'URL' | 'logoURL' | 'autocomplete' | 'textarea' | 'select' | 'checkbox' | 'chips' = 'text';
@Input('label') label: string;
/** Text */
@ViewChild('input') input: ElementRef;
/** Textarea options */
@Input('rows') rows: number = 3;
/** Select | chips available options */
@ -221,6 +223,9 @@ export class InputComponent implements OnInit, OnDestroy, OnChanges {
@HostListener('document:click', ['$event'])
clickOut(event) {
this.focused = !!this.elementRef.nativeElement.contains(event.target);
if(!this.focused && this.input) {
this.input.nativeElement.setSelectionRange(0,0);
}
this.focusEmitter.emit(this.focused);
}