Comment textarea focus on init

This commit is contained in:
Chocobozzz 2017-12-29 09:18:00 +01:00
parent 59651eee56
commit eacf925ea6
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 10 additions and 3 deletions

View File

@ -1,6 +1,6 @@
<form novalidate [formGroup]="form" (ngSubmit)="formValidated()">
<div class="form-group">
<textarea placeholder="Add comment..." formControlName="text" [ngClass]="{ 'input-error': formErrors['text'] }">
<textarea placeholder="Add comment..." formControlName="text" [ngClass]="{ 'input-error': formErrors['text'] }" #textarea>
</textarea>
<div *ngIf="formErrors.text" class="form-error">
{{ formErrors.text }}

View File

@ -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<VideoCommentCreate>()
@ -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 () {

View File

@ -10,7 +10,7 @@
</div>
<my-video-comment-add
*ngIf="isUserLoggedIn() && inReplyToCommentId === comment.id" [video]="video" [parentComment]="comment"
*ngIf="isUserLoggedIn() && inReplyToCommentId === comment.id" [video]="video" [parentComment]="comment" [focusOnInit]="true"
(commentCreated)="onCommentReplyCreated($event)"
></my-video-comment-add>