From eacf925ea668ba48c30f4e8e3c117d8daaebfe77 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 29 Dec 2017 09:18:00 +0100 Subject: [PATCH] Comment textarea focus on init --- .../comment/video-comment-add.component.html | 2 +- .../+video-watch/comment/video-comment-add.component.ts | 9 ++++++++- .../+video-watch/comment/video-comment.component.html | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/client/src/app/videos/+video-watch/comment/video-comment-add.component.html b/client/src/app/videos/+video-watch/comment/video-comment-add.component.html index 792053614..365fc8f6c 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment-add.component.html +++ b/client/src/app/videos/+video-watch/comment/video-comment-add.component.html @@ -1,6 +1,6 @@
-
{{ formErrors.text }} diff --git a/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts b/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts index d05232202..a6525987e 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts +++ b/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' +import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' import { FormBuilder, FormGroup } from '@angular/forms' import { NotificationsService } from 'angular2-notifications' import { Observable } from 'rxjs/Observable' @@ -17,6 +17,7 @@ import { VideoCommentService } from './video-comment.service' export class VideoCommentAddComponent extends FormReactive implements OnInit { @Input() video: Video @Input() parentComment: VideoComment + @Input() focusOnInit = false @Output() commentCreated = new EventEmitter() @@ -28,6 +29,8 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit { 'text': VIDEO_COMMENT_TEXT.MESSAGES } + @ViewChild('textarea') private textareaElement: ElementRef + constructor ( private formBuilder: FormBuilder, private notificationsService: NotificationsService, @@ -46,6 +49,10 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit { ngOnInit () { this.buildForm() + + if (this.focusOnInit === true) { + this.textareaElement.nativeElement.focus() + } } formValidated () { diff --git a/client/src/app/videos/+video-watch/comment/video-comment.component.html b/client/src/app/videos/+video-watch/comment/video-comment.component.html index 9608a1033..ffaf722cd 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment.component.html +++ b/client/src/app/videos/+video-watch/comment/video-comment.component.html @@ -10,7 +10,7 @@
-- 2.41.0