From 1619cb6f2b5a1834b48b8fbe4eefcc445be3cf3b Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 9 Apr 2021 13:01:07 +0000 Subject: [PATCH] [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 --- sharedComponents/input/input.component.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sharedComponents/input/input.component.ts b/sharedComponents/input/input.component.ts index 45c88911..1dfbebf0 100644 --- a/sharedComponents/input/input.component.ts +++ b/sharedComponents/input/input.component.ts @@ -51,7 +51,7 @@ export interface Option {
- +
@@ -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); }