I am trying to stop the Enter from submitting my button and rather make it point to another function. I tried trapping the Enter via the Host Listener and then do preventDefault()
on it to stop it from firing.
My template in my component looks like this:
<mat-dialog-content class="dialog-content">{{data.content | translate}}</mat-dialog-content>
<div>
<mat-button-toggle-group>
<button type="button" matDialogClose (click)="dialogRef.close()">{{uppercase }}</button>
<button type="button" (click)="dialogRef.close(true)" cdkFocusInitial>{{uppercase}}</button>
</mat-button-toggle-group>
</div>
At the top of my component code:
export enum KEY_CODE {
ENTER_KEY = 13
}
Inside my export class:
@HostListener('window:keyup', ['$event'])
keyEventUp(event: KeyboardEvent) {
if (event.keyCode === KEY_CODE.ENTER_KEY) {
event.preventDefault();
event.stopPropagation();
return false;
}
}