[ADF-5007] Comments - textarea Escape event cannot be canceled (#5266)

* use keydown event

* cancel event propagation

* update tests
This commit is contained in:
Cilibiu Bogdan 2019-12-03 16:11:22 +02:00 committed by Eugenio Romano
parent f2cbd0cd9a
commit 79eb9365c8
3 changed files with 5 additions and 4 deletions

View File

@ -4,7 +4,7 @@
</div>
<div class="adf-comments-input-container" *ngIf="!isReadOnly()">
<mat-form-field class="adf-full-width">
<textarea (keyup.escape)="clear()" matInput id="comment-input" placeholder="{{'COMMENTS.ADD' | translate}}" [(ngModel)]="message"></textarea>
<textarea (keydown.escape)="clear($event)" matInput id="comment-input" placeholder="{{'COMMENTS.ADD' | translate}}" [(ngModel)]="message"></textarea>
</mat-form-field>
<div class="adf-comments-input-actions">

View File

@ -277,7 +277,7 @@ describe('CommentsComponent', () => {
}));
it('should clear comment when escape key is pressed', async(() => {
const event = new KeyboardEvent('keyup', {'key': 'Escape'});
const event = new KeyboardEvent('keydown', {'key': 'Escape'});
let element = fixture.nativeElement.querySelector('#comment-input');
element.dispatchEvent(event);
fixture.detectChanges();
@ -365,7 +365,7 @@ describe('CommentsComponent', () => {
}));
it('should clear comment when escape key is pressed', async(() => {
const event = new KeyboardEvent('keyup', {'key': 'Escape'});
const event = new KeyboardEvent('keydown', {'key': 'Escape'});
let element = fixture.nativeElement.querySelector('#comment-input');
element.dispatchEvent(event);
fixture.detectChanges();

View File

@ -165,7 +165,8 @@ export class CommentsComponent implements OnChanges {
}
}
clear(): void {
clear(event: KeyboardEvent): void {
event.stopPropagation();
this.message = '';
}