[FIX] web: prevent mobile keyboard popping up on tablet
Before this commit, when loading a view containing a searchbar on a tablet, the device's keyboard is appearing once the searchbar's field is autofocused. Thanks to the backport of the mobile OS detection (see PR odoo/odoo#75455 ), we are now able to properly target mobile OS (independent of the screen's resolution) instead of only small screens. closes odoo/odoo#75880 X-original-commit: b1a7296f060811153039ef73140e78ea702088a1 Signed-off-by: Adrien Dieudonné (adr) <adr@odoo.com> Signed-off-by: Pierre Paridans <pparidans@users.noreply.github.com>
This commit is contained in:
@@ -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]';
|
||||
|
||||
@@ -592,7 +592,7 @@
|
||||
</div>
|
||||
<input type="text"
|
||||
class="o_searchview_input"
|
||||
autofocus=""
|
||||
t-att-autofocus="!env.device.isMobileDevice"
|
||||
accesskey="Q"
|
||||
placeholder="Search..."
|
||||
role="searchbox"
|
||||
|
||||
@@ -252,5 +252,48 @@ odoo.define('web.control_panel_tests', function (require) {
|
||||
|
||||
controlPanel.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('search field should be autofocused', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
const controlPanel = await createControlPanel({
|
||||
model: 'partner',
|
||||
arch: '<search/>',
|
||||
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: '<search/>',
|
||||
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();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user