diff --git a/addons/web/static/src/core/commands/command_palette.js b/addons/web/static/src/core/commands/command_palette.js index 607df17fbdb..9fed6b8185f 100644 --- a/addons/web/static/src/core/commands/command_palette.js +++ b/addons/web/static/src/core/commands/command_palette.js @@ -182,6 +182,7 @@ export class CommandPalette extends Component { const { namespace, searchValue } = this.processSearchValue(config.searchValue || ""); this.switchNamespace(namespace); + this.state.searchValue = searchValue; await this.race.add(this.search(searchValue)); } @@ -306,7 +307,6 @@ export class CommandPalette extends Component { } async search(searchValue) { - this.state.searchValue = searchValue; await this.setCommands(this.state.namespace, { searchValue, activeElement: this.activeElement, @@ -322,7 +322,7 @@ export class CommandPalette extends Component { if (namespace !== "default" && this.state.namespace !== namespace) { this.switchNamespace(namespace); } - this.inputRef.el.value = searchValue; + this.state.searchValue = searchValue; this.searchValuePromise = this.lastDebounceSearch(searchValue).catch(() => { this.searchValuePromise = null; }); @@ -335,6 +335,7 @@ export class CommandPalette extends Component { onKeyDown(ev) { if (ev.key.toLowerCase() === "backspace" && !ev.target.value.length && !ev.repeat) { this.switchNamespace("default"); + this.state.searchValue = ""; this.searchValuePromise = this.lastDebounceSearch("").catch(() => { this.searchValuePromise = null; }); diff --git a/addons/web/static/tests/core/commands/command_palette_tests.js b/addons/web/static/tests/core/commands/command_palette_tests.js index e306a914761..a27d5fae5de 100644 --- a/addons/web/static/tests/core/commands/command_palette_tests.js +++ b/addons/web/static/tests/core/commands/command_palette_tests.js @@ -1595,3 +1595,57 @@ QUnit.test("checks that href is correctly used", async (assert) => { await nextTick(); assert.verifySteps(["command_with_link_clicked"]); }); + +QUnit.test("searchValue must not change without edition", async (assert) => { + const provideDef = makeDeferred(); + let debounceDef; + + patchWithCleanup(browser, { + clearTimeout: () => {}, + setTimeout: async (later) => { + // debounce the search "deb" + await debounceDef; + later(); + }, + }); + + mount(TestComponent, target, { env }); + const providers = [ + { + provide: async (env, { searchValue }) => { + if (searchValue === "abc") { + await provideDef; + } + return [ + { + name: searchValue, + action: () => {}, + }, + ]; + }, + }, + ]; + const config = { + providers, + }; + env.services.dialog.add(CommandPalette, { + config, + }); + + await nextTick(); + + await editSearchBar("abc"); + assert.strictEqual(target.querySelector(".o_command_palette_search input").value, "abc"); + + debounceDef = makeDeferred(); + await editSearchBar("deb"); + assert.strictEqual(target.querySelector(".o_command_palette_search input").value, "deb"); + + provideDef.resolve(); + await nextTick(); + assert.strictEqual(target.querySelector(".o_command_palette_search input").value, "deb"); + + debounceDef.resolve(); + await nextTick(); + assert.strictEqual(target.querySelector(".o_command_palette_search input").value, "deb"); +});