diff --git a/addons/web/static/src/legacy/js/core/custom_hooks.js b/addons/web/static/src/legacy/js/core/custom_hooks.js
index 8b5d9834d0a..1a9ff8b81fd 100644
--- a/addons/web/static/src/legacy/js/core/custom_hooks.js
+++ b/addons/web/static/src/legacy/js/core/custom_hooks.js
@@ -16,7 +16,7 @@ odoo.define('web.custom_hooks', function (require) {
function useAutofocus(params = {}) {
const comp = Component.current;
// Prevent autofocus in mobile
- if (comp.env.device.isMobile) {
+ if (comp.env.device.isMobileDevice) {
return () => {};
}
const selector = params.selector || '[autofocus]';
diff --git a/addons/web/static/src/legacy/xml/base.xml b/addons/web/static/src/legacy/xml/base.xml
index f2e4e3228ba..ed071fc1583 100644
--- a/addons/web/static/src/legacy/xml/base.xml
+++ b/addons/web/static/src/legacy/xml/base.xml
@@ -592,7 +592,7 @@
',
+ data: this.data,
+ env: {
+ device: {
+ isMobileDevice: false,
+ },
+ },
+ });
+
+ assert.containsOnce(controlPanel, '.o_searchview_input', "has a search field");
+ assert.containsOnce(controlPanel, '.o_searchview_input:focus-within',
+ "has autofocused search field");
+
+ controlPanel.destroy();
+ });
+
+ QUnit.test("search field's autofocus should be disabled on mobile device", async function (assert) {
+ assert.expect(2);
+
+ const controlPanel = await createControlPanel({
+ model: 'partner',
+ arch: '',
+ data: this.data,
+ env: {
+ device: {
+ isMobileDevice: true,
+ },
+ },
+ });
+
+ assert.containsOnce(controlPanel, '.o_searchview_input', "has a search field");
+ assert.containsNone(controlPanel, '.o_searchview_input:focus-within',
+ "hasn't autofocused search field");
+
+ controlPanel.destroy();
+ });
+
});
});