Skip to content

Commit 0f9efb4

Browse files
Chat Editing: focus input after Edit menu item clicked (#29774)
1 parent c5c5a20 commit 0f9efb4

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ class Chat extends Widget<Properties> {
211211
isLoading,
212212
onMessageEditingStart: (e) => {
213213
this._messageEditingStartHandler(e);
214+
215+
return () => this.focus();
214216
},
215217
onMessageDeleting: (e) => {
216218
this._messageDeletingHandler(e);

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ class MessageBox extends DOMComponent<MessageBox, Properties> {
117117
const $editingPreview = $('<div>').prependTo(this.element());
118118
const { text } = this.option();
119119

120-
$editingPreview.get(0).addEventListener('animationend', () => {
121-
this._textArea.focus();
122-
}, { once: true });
123-
124120
this._editingPreview = this._createComponent($editingPreview, EditingPreview, {
125121
text,
126122
onCancel: () => this._cancelMessageEdit(),

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export interface Properties extends WidgetOptions<MessageList> {
8888
showAvatar: boolean;
8989
showUserName: boolean;
9090
showMessageTimestamp: boolean;
91-
onMessageEditingStart?: (e: MessageEditingEvent) => void;
91+
onMessageEditingStart?: (e: MessageEditingEvent) => () => void;
9292
onMessageDeleting?: (e: MessageEditingEvent) => void;
9393
onEscapeKeyPressed?: (e: KeyboardEvent) => void;
9494
}
@@ -284,7 +284,14 @@ class MessageList extends Widget<Properties> {
284284
text: editText,
285285
disabled: isEditActionDisabled(message),
286286
onClick: (e: ItemClick): void => {
287-
onMessageEditingStart?.({ event: e.event, message });
287+
const onMessageEditStarted = onMessageEditingStart?.({ event: e.event, message });
288+
289+
const onContextMenuHidden = (): void => {
290+
this._contextMenu.off('hidden', onContextMenuHidden);
291+
onMessageEditStarted?.();
292+
};
293+
294+
this._contextMenu.on('hidden', onContextMenuHidden);
288295
},
289296
});
290297
}

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

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ QUnit.module('Chat', () => {
427427
assert.strictEqual(this.$textArea.hasClass(FOCUSED_STATE_CLASS), true, 'input is focused');
428428
});
429429

430-
QUnit.skip('Input focused after context menu is hidden', function(assert) {
430+
QUnit.testInActiveWindow('Input not focused after context menu is hidden by outside click', function(assert) {
431431
if(!isDesktopDevice()) {
432432
assert.ok(true, 'Test is not applicable for mobile devices');
433433
return;
@@ -454,7 +454,7 @@ QUnit.module('Chat', () => {
454454
pointerMock($bubbles.eq(0)).click();
455455

456456
assert.strictEqual(this.getContextMenu().option('visible'), false, 'context menu is hidden');
457-
assert.strictEqual(this.$textArea.hasClass(FOCUSED_STATE_CLASS), true, 'input is focused');
457+
assert.strictEqual(this.$textArea.hasClass(FOCUSED_STATE_CLASS), false, 'input is focused');
458458
});
459459

460460
QUnit.testInActiveWindow('Input should be blurred after context menu is shown', function(assert) {
@@ -935,7 +935,7 @@ QUnit.module('Chat', () => {
935935
});
936936
});
937937

938-
QUnit.skip('editing preview should be shown after the Edit button is clicked if cancel promise rejected', function(assert) {
938+
QUnit.testInActiveWindow('editing preview should be shown after the Edit button is clicked if cancel promise rejected', function(assert) {
939939
if(!isDesktopDevice()) {
940940
assert.ok(true, 'Test is not applicable for mobile devices');
941941
return;
@@ -1082,7 +1082,7 @@ QUnit.module('Chat', () => {
10821082
}, ANIMATION_TIMEOUT);
10831083
});
10841084

1085-
QUnit.skip('message box should have editing message text and focus after the Edit button is clicked and not cancelled', function(assert) {
1085+
QUnit.testInActiveWindow('message box should have editing message text and focus after the Edit button is clicked and not cancelled', function(assert) {
10861086
if(!isDesktopDevice()) {
10871087
assert.ok(true, 'Test is not applicable for mobile devices');
10881088
return;
@@ -1111,6 +1111,37 @@ QUnit.module('Chat', () => {
11111111
assert.strictEqual(this.textArea.option('value'), 'b', 'input contains editing message text');
11121112
assert.strictEqual(this.$textArea.hasClass(FOCUSED_STATE_CLASS), true, 'input is focused');
11131113
});
1114+
1115+
QUnit.testInActiveWindow('message box should have editing message text and focus after the Edit was triggered from keyboard', function(assert) {
1116+
if(!isDesktopDevice()) {
1117+
assert.ok(true, 'Test is not applicable for mobile devices');
1118+
return;
1119+
}
1120+
1121+
const items = [
1122+
{ text: 'a', author: userFirst },
1123+
{ text: 'b', author: userSecond },
1124+
];
1125+
1126+
this.reinit({
1127+
focusStateEnabled: true,
1128+
user: userSecond,
1129+
editing: {
1130+
allowUpdating: true
1131+
},
1132+
items,
1133+
});
1134+
1135+
const $bubbles = this.getBubbles();
1136+
$bubbles.eq(1).trigger('dxcontextmenu');
1137+
1138+
keyboardMock(this.getContextMenu().itemsContainer())
1139+
.press('down')
1140+
.press('enter');
1141+
1142+
assert.strictEqual(this.textArea.option('value'), 'b', 'input contains editing message text');
1143+
assert.strictEqual(this.$textArea.hasClass(FOCUSED_STATE_CLASS), true, 'input is focused');
1144+
});
11141145
});
11151146

11161147
QUnit.module('Events', () => {

0 commit comments

Comments
 (0)