MOBILE-3320 core: Prevent new line to be shown before submit

main
Pau Ferrer Ocaña 2021-05-25 14:26:32 +02:00
parent 5a15d1722f
commit 871a36f7a2
2 changed files with 39 additions and 4 deletions

View File

@ -1,7 +1,21 @@
<form #messageForm> <form #messageForm>
<textarea class="core-send-message-input" [core-auto-focus]="showKeyboard" [placeholder]="placeholder" rows="1" core-auto-rows <textarea
[(ngModel)]="message" name="message" (onResize)="textareaResized()" (keyup.enter)="enterClicked($event)" class="core-send-message-input"
(keyup.control.enter)="enterClicked($event, 'control')" (keyup.meta.enter)="enterClicked($event, 'meta')"></textarea> [core-auto-focus]="showKeyboard"
[placeholder]="placeholder"
rows="1"
core-auto-rows
[(ngModel)]="message"
name="message"
(onResize)="textareaResized()"
(keyup.enter)="enterKeyUp($event)"
(keyup.control.enter)="enterKeyUp($event, 'control')"
(keyup.meta.enter)="enterKeyUp($event, 'meta')"
(keydown.enter)="enterKeyDown($event)"
(keydown.control.enter)="enterKeyDown($event, 'control')"
(keydown.meta.enter)="enterKeyDown($event, 'meta')"
>
</textarea>
<ion-button fill="clear" size="large" type="submit" [disabled]="!message || sendDisabled" <ion-button fill="clear" size="large" type="submit" [disabled]="!message || sendDisabled"
[attr.aria-label]="'core.send' | translate" [core-suppress-events] (click)="submitForm($event)"> [attr.aria-label]="'core.send' | translate" [core-suppress-events] (click)="submitForm($event)">
<ion-icon name="send" color="dark" slot="icon-only" aria-hidden="true"></ion-icon> <ion-icon name="send" color="dark" slot="icon-only" aria-hidden="true"></ion-icon>

View File

@ -103,13 +103,34 @@ export class CoreSendMessageFormComponent implements OnInit {
this.onResize.emit(); this.onResize.emit();
} }
/**
* A11y key functionality that prevents keyDown events.
*
* @param e Event.
*/
enterKeyDown(e: KeyboardEvent, other?: string): void {
if (this.sendDisabled) {
return;
}
if (this.sendOnEnter && !other) {
// Enter clicked, send the message.
e.preventDefault();
e.stopPropagation();
} else if (!this.sendOnEnter && !CoreApp.isMobile() && other == 'control') {
// Cmd+Enter or Ctrl+Enter, send message.
e.preventDefault();
e.stopPropagation();
}
}
/** /**
* Enter key clicked. * Enter key clicked.
* *
* @param e Event. * @param e Event.
* @param other The name of the other key that was clicked, undefined if no other key. * @param other The name of the other key that was clicked, undefined if no other key.
*/ */
enterClicked(e: Event, other?: string): void { enterKeyUp(e: Event, other?: string): void {
if (this.sendDisabled) { if (this.sendDisabled) {
return; return;
} }