diff --git a/addons/web/static/src/search/search_bar/search_bar.js b/addons/web/static/src/search/search_bar/search_bar.js
index a2ed1ec39bf..dd43fc0e1aa 100644
--- a/addons/web/static/src/search/search_bar/search_bar.js
+++ b/addons/web/static/src/search/search_bar/search_bar.js
@@ -41,9 +41,10 @@ export class SearchBar extends Component {
this.keepLast = new KeepLast();
- this.inputRef = this.env.config.disableSearchBarAutofocus
- ? useRef("autofocus")
- : useAutofocus();
+ this.inputRef =
+ this.env.config.disableSearchBarAutofocus || !this.props.autofocus
+ ? useRef("autofocus")
+ : useAutofocus();
useBus(this.env.searchModel, "focus-search", () => {
this.inputRef.el.focus();
@@ -572,4 +573,9 @@ SearchBar.template = "web.SearchBar";
SearchBar.components = {
SearchBarMenu,
};
-SearchBar.props = {};
+SearchBar.props = {
+ autofocus: { type: Boolean, optional: true },
+};
+SearchBar.defaultProps = {
+ autofocus: true,
+};
diff --git a/addons/web/static/src/views/list/list_controller.js b/addons/web/static/src/views/list/list_controller.js
index 9929ee7d01c..e4a2a41d067 100644
--- a/addons/web/static/src/views/list/list_controller.js
+++ b/addons/web/static/src/views/list/list_controller.js
@@ -27,7 +27,15 @@ import { DropdownItem } from "@web/core/dropdown/dropdown_item";
import { CogMenu } from "@web/search/cog_menu/cog_menu";
import { ActionMenusItems } from "@web/search/cog_menu/action_menus_items";
-import { Component, onMounted, onWillStart, useEffect, useRef, useSubEnv } from "@odoo/owl";
+import {
+ Component,
+ onMounted,
+ onWillPatch,
+ onWillStart,
+ useEffect,
+ useRef,
+ useSubEnv,
+} from "@odoo/owl";
// -----------------------------------------------------------------------------
@@ -146,6 +154,10 @@ export class ListController extends Component {
() => [this.model.root.selection.length]
);
this.searchBarToggler = useSearchBarToggler();
+ this.firstLoad = true;
+ onWillPatch(() => {
+ this.firstLoad = false;
+ });
}
get modelParams() {
diff --git a/addons/web/static/src/views/list/list_controller.xml b/addons/web/static/src/views/list/list_controller.xml
index 8c0a00f8558..4c036f9b536 100644
--- a/addons/web/static/src/views/list/list_controller.xml
+++ b/addons/web/static/src/views/list/list_controller.xml
@@ -32,7 +32,7 @@
-
+
diff --git a/addons/web/static/tests/views/list_view_tests.js b/addons/web/static/tests/views/list_view_tests.js
index cfac9d3fa25..69e78007458 100644
--- a/addons/web/static/tests/views/list_view_tests.js
+++ b/addons/web/static/tests/views/list_view_tests.js
@@ -492,6 +492,31 @@ QUnit.module("Views", (hooks) => {
assert.containsNone(target, ".o_list_button_add", "should not have the 'Create' button");
});
+ QUnit.test(
+ "searchbar in listview doesn't take focus after unselected all items",
+ async function (assert) {
+ await makeView({
+ type: "list",
+ resModel: "foo",
+ serverData,
+ arch: ``,
+ });
+
+ assert.equal(
+ document.activeElement,
+ target.querySelector(".o_searchview_input"),
+ "The search input should be have the focus"
+ );
+ await click(target, `tbody .o_data_row:first-child input[type="checkbox"]`);
+ await click(target, `tbody input[type="checkbox"]:checked`);
+ assert.notEqual(
+ document.activeElement,
+ target.querySelector(".o_searchview_input"),
+ "The search input shouldn't have the focus"
+ );
+ }
+ );
+
QUnit.test('list with delete="0"', async function (assert) {
await makeView({
type: "list",