Skip to content

Commit 611b5e1

Browse files
authored
Chat - enter press should add a new line in TextArea on Mobile devices (T1293840)
1 parent ad869b8 commit 611b5e1

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

packages/devextreme/js/__internal/ui/chat/messagebox.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { NativeEventInfo } from '@js/common/core/events';
22
import messageLocalization from '@js/common/core/localization/message';
3+
import devices from '@js/core/devices';
34
import $, { type dxElementWrapper } from '@js/core/renderer';
45
import type { ClickEvent } from '@js/ui/button';
56
import Button from '@js/ui/button';
@@ -25,6 +26,8 @@ export type MessageEnteredEvent =
2526

2627
export type TypingStartEvent = NativeEventInfo<MessageBox, UIEvent & { target: HTMLInputElement }>;
2728

29+
const isMobile = (): boolean => devices.current().deviceType !== 'desktop';
30+
2831
export interface Properties extends DOMComponentProperties<MessageBox> {
2932
activeStateEnabled?: boolean;
3033

@@ -160,14 +163,18 @@ class MessageBox extends DOMComponent<MessageBox, Properties> {
160163
this._updateTypingEndTimeout();
161164
},
162165
onEnterKey: (e: EnterKeyEvent): void => {
166+
if (isMobile()) {
167+
return;
168+
}
169+
163170
if (!e.event?.shiftKey) {
164171
this._sendHandler(e);
165172
}
166173
},
167174
});
168175

169176
this._textArea.registerKeyHandler('enter', (event: KeyboardEvent) => {
170-
if (!event.shiftKey && this._isValuableTextEntered()) {
177+
if (!event.shiftKey && this._isValuableTextEntered() && !isMobile()) {
171178
event.preventDefault();
172179
}
173180
});

packages/devextreme/testing/tests/DevExpress.ui.widgets/chatParts/messageBox.tests.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import EditingPreview, {
1717
import {
1818
FOCUSED_STATE_CLASS,
1919
} from '__internal/core/widget/widget';
20+
import { shouldSkipOnDesktop, shouldSkipOnMobile } from '../../../helpers/device.js';
2021

2122
const TEXTEDITOR_INPUT_CLASS = 'dx-texteditor-input';
2223

@@ -186,6 +187,10 @@ QUnit.module('MessageBox', moduleConfig, () => {
186187
});
187188

188189
QUnit.test('should be fired on enter key if the textarea input contains a value', function(assert) {
190+
if(shouldSkipOnMobile(assert)) {
191+
return;
192+
}
193+
189194
const onMessageEnteredStub = sinon.stub();
190195

191196
this.reinit({ onMessageEntered: onMessageEnteredStub });
@@ -283,6 +288,10 @@ QUnit.module('MessageBox', moduleConfig, () => {
283288
});
284289

285290
QUnit.test('should be fired with correct arguments when enter is pressed', function(assert) {
291+
if(shouldSkipOnMobile(assert)) {
292+
return;
293+
}
294+
286295
assert.expect(6);
287296

288297
const text = ' new text message ';
@@ -306,6 +315,24 @@ QUnit.module('MessageBox', moduleConfig, () => {
306315
.keyDown('enter')
307316
.keyUp('enter');
308317
});
318+
319+
QUnit.test('should not send message on enter key on mobile devices (T1293840)', function(assert) {
320+
if(shouldSkipOnDesktop(assert)) {
321+
return;
322+
}
323+
324+
const onMessageEnteredStub = sinon.stub();
325+
326+
this.reinit({ onMessageEntered: onMessageEnteredStub });
327+
328+
keyboardMock(this.$input)
329+
.focus()
330+
.type('new text message')
331+
.keyDown('enter')
332+
.keyUp('enter');
333+
334+
assert.strictEqual(onMessageEnteredStub.callCount, 0);
335+
});
309336
});
310337

311338
QUnit.module('onMessageEditCanceled event', () => {
@@ -693,6 +720,10 @@ QUnit.module('MessageBox', moduleConfig, () => {
693720
});
694721

695722
QUnit.test('textarea should be cleared on enter key when some text is entered', function(assert) {
723+
if(shouldSkipOnMobile(assert)) {
724+
return;
725+
}
726+
696727
keyboardMock(this.$input)
697728
.focus()
698729
.type('some text')
@@ -703,6 +734,10 @@ QUnit.module('MessageBox', moduleConfig, () => {
703734
});
704735

705736
QUnit.test('enter keydown event should be prevented if input text has non-space characters', function(assert) {
737+
if(shouldSkipOnMobile(assert)) {
738+
return;
739+
}
740+
706741
const enterKeyDownEvent = $.Event('keydown', { key: 'enter' });
707742

708743
keyboardMock(this.$input).type('1');
@@ -733,6 +768,10 @@ QUnit.module('MessageBox', moduleConfig, () => {
733768
});
734769

735770
QUnit.test('textarea should restore its height after enter press when multiline text was entered', function(assert) {
771+
if(shouldSkipOnMobile(assert)) {
772+
return;
773+
}
774+
736775
const initialTextAreaHeight = this.$textArea.height();
737776

738777
keyboardMock(this.$input)

0 commit comments

Comments
 (0)