summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/components
diff options
context:
space:
mode:
authorPaul Morelle <pmo@odoo.com>2020-11-18 12:13:35 +0000
committerPaul Morelle <pmo@odoo.com>2020-11-18 15:30:28 +0000
commitaddd392a1b5f7e569c65a4503152ba0bdfe49eb3 (patch)
tree446e85c76509d207e2b2aa2a029b297ffb30507d /addons/mail/static/src/components
parentf22c34e7f61f7f8ac5b9ab7f9579cc4e6dd0e334 (diff)
[FIX] mail: select first contact in new message box
In previous versions of Odoo, in the New message box, typing a few letters of the name of your recipient and pressing Enter would automatically select the conversation with this contact. Since 14.0, one has to select the first result with the Down key. This commit restores the previous behavior by using the [`autofocus`](https://api.jqueryui.com/autocomplete/#option-autoFocus) option. closes odoo/odoo#61886 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/src/components')
-rw-r--r--addons/mail/static/src/components/autocomplete_input/autocomplete_input.js1
-rw-r--r--addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js42
2 files changed, 43 insertions, 0 deletions
diff --git a/addons/mail/static/src/components/autocomplete_input/autocomplete_input.js b/addons/mail/static/src/components/autocomplete_input/autocomplete_input.js
index e9bb5286ee2..c80bbafc4c7 100644
--- a/addons/mail/static/src/components/autocomplete_input/autocomplete_input.js
+++ b/addons/mail/static/src/components/autocomplete_input/autocomplete_input.js
@@ -11,6 +11,7 @@ class AutocompleteInput extends Component {
}
let args = {
+ autoFocus: true,
select: (ev, ui) => this._onAutocompleteSelect(ev, ui),
source: (req, res) => this._onAutocompleteSource(req, res),
focus: ev => this._onAutocompleteFocus(ev),
diff --git a/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js b/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js
index c0a6bf1295f..15baa5472ec 100644
--- a/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js
+++ b/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js
@@ -378,6 +378,48 @@ QUnit.test('open chat from "new message" chat window should open chat in place o
);
});
+QUnit.test('new message autocomplete should automatically select first result', async function (assert) {
+ assert.expect(1);
+
+ this.data['res.partner'].records.push({ id: 131, name: "Partner 131" });
+ this.data['res.users'].records.push({ partner_id: 131 });
+ const imSearchDef = makeDeferred();
+ await this.start({
+ async mockRPC(route, args) {
+ const res = await this._super(...arguments);
+ if (args.method === 'im_search') {
+ imSearchDef.resolve();
+ }
+ return res;
+ },
+ });
+
+ // open "new message" chat window
+ await afterNextRender(() =>
+ document.querySelector(`.o_MessagingMenu_toggler`).click()
+ );
+ await afterNextRender(() =>
+ document.querySelector(`.o_MessagingMenu_newMessageButton`).click()
+ );
+
+ // search for a user in "new message" autocomplete
+ document.execCommand('insertText', false, "131");
+ document.querySelector(`.o_ChatWindow_newMessageFormInput`)
+ .dispatchEvent(new window.KeyboardEvent('keydown'));
+ document.querySelector(`.o_ChatWindow_newMessageFormInput`)
+ .dispatchEvent(new window.KeyboardEvent('keyup'));
+ // Wait for search RPC to be resolved. The following await lines are
+ // necessary because autocomplete is an external lib therefore it is not
+ // possible to use `afterNextRender`.
+ await imSearchDef;
+ await nextAnimationFrame();
+ assert.hasClass(
+ document.querySelector('.ui-autocomplete .ui-menu-item a'),
+ 'ui-state-active',
+ "first autocomplete result should be automatically selected",
+ );
+});
+
QUnit.test('chat window: basic rendering', async function (assert) {
assert.expect(11);