diff --git a/addons/mail/static/src/components/composer/composer.js b/addons/mail/static/src/components/composer/composer.js index 4434697f8fb..991d5fc4482 100644 --- a/addons/mail/static/src/components/composer/composer.js +++ b/addons/mail/static/src/components/composer/composer.js @@ -261,6 +261,7 @@ class Composer extends Component { */ _onClickSend() { this._postMessage(); + this.focus(); } /** diff --git a/addons/mail/static/src/components/thread_view/thread_view_tests.js b/addons/mail/static/src/components/thread_view/thread_view_tests.js index 2c81214c024..8e95fd80d4c 100644 --- a/addons/mail/static/src/components/thread_view/thread_view_tests.js +++ b/addons/mail/static/src/components/thread_view/thread_view_tests.js @@ -1697,10 +1697,11 @@ QUnit.test('first unseen message should be directly preceded by the new message document.querySelector('.o_ComposerTextInput_textarea').focus(); await afterNextRender(() => document.execCommand('insertText', false, "/who")); await afterNextRender(() => { - document.querySelector('.o_Composer_buttonSend').focus(); document.querySelector('.o_Composer_buttonSend').click(); }); + // composer is focused by default, we remove that focus + document.querySelector('.o_ComposerTextInput_textarea').blur(); // simulate receiving a message await afterNextRender(() => this.env.services.rpc({ route: '/mail/chat_post', @@ -1732,6 +1733,32 @@ QUnit.test('first unseen message should be directly preceded by the new message ); }); +QUnit.test('composer should be focused automatically after clicking on the send button [REQUIRE FOCUS]', async function (assert) { + assert.expect(1); + + this.data['mail.channel'].records.push({id: 20,}); + await this.start(); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel' + }); + const threadViewer = this.env.models['mail.thread_viewer'].create({ + hasThreadView: true, + thread: [['link', thread]], + }); + await this.createThreadViewComponent(threadViewer.threadView, { hasComposer: true }); + document.querySelector('.o_ComposerTextInput_textarea').focus(); + await afterNextRender(() => document.execCommand('insertText', false, "Dummy Message")); + await afterNextRender(() => { + document.querySelector('.o_Composer_buttonSend').click(); + }); + assert.hasClass( + document.querySelector('.o_Composer'), + 'o-focused', + "composer should be focused automatically after clicking on the send button" + ); +}); + }); }); });