diff --git a/addons/mail/static/src/core/common/suggestion_hook.js b/addons/mail/static/src/core/common/suggestion_hook.js index 5519de70d04..59c3ee5342c 100644 --- a/addons/mail/static/src/core/common/suggestion_hook.js +++ b/addons/mail/static/src/core/common/suggestion_hook.js @@ -136,7 +136,7 @@ export function useSuggestion() { ); const { type, mainSuggestions, extraSuggestions = [] } = suggestions; if (!mainSuggestions.length && !extraSuggestions.length) { - self.clearSearch(); + self.state.items = undefined; return; } // arbitrary limit to avoid displaying too many elements at once diff --git a/addons/mail/static/src/utils/common/hooks.js b/addons/mail/static/src/utils/common/hooks.js index 0671ec83451..8b45ae7bdef 100644 --- a/addons/mail/static/src/utils/common/hooks.js +++ b/addons/mail/static/src/utils/common/hooks.js @@ -288,9 +288,11 @@ export function useSelection({ refName, model, preserveOnClickAwayPredicate = () }); onMounted(() => { document.addEventListener("selectionchange", onSelectionChange); + document.addEventListener("input", onSelectionChange); }); onWillUnmount(() => { document.removeEventListener("selectionchange", onSelectionChange); + document.removeEventListener("input", onSelectionChange); }); return { restore() { diff --git a/addons/mail/static/tests/discuss/core/suggestion_tests.js b/addons/mail/static/tests/discuss/core/suggestion_tests.js index 997a352e791..837b6ce5c32 100644 --- a/addons/mail/static/tests/discuss/core/suggestion_tests.js +++ b/addons/mail/static/tests/discuss/core/suggestion_tests.js @@ -2,7 +2,13 @@ import { Composer } from "@mail/core/common/composer"; import { Command } from "@mail/../tests/helpers/command"; -import { click, insertText, start, startServer } from "@mail/../tests/helpers/test_utils"; +import { + afterNextRender, + click, + insertText, + start, + startServer, +} from "@mail/../tests/helpers/test_utils"; import { patchWithCleanup } from "@web/../tests/helpers/utils"; @@ -124,3 +130,22 @@ QUnit.test("Sort partner suggestions by recent chats", async (assert) => { assert.strictEqual($(".o-mail-Composer-suggestion").eq(1).text(), "User 1"); assert.strictEqual($(".o-mail-Composer-suggestion").eq(2).text(), "User 3"); }); + +QUnit.test("suggestion are shown after deleting a character", async (assert) => { + const pyEnv = await startServer(); + const channelId = pyEnv["discuss.channel"].create({ + name: "General", + channel_type: "channel", + }); + const { openDiscuss } = await start(); + await openDiscuss(channelId); + await insertText(".o-mail-Composer-input", "/"); + await insertText(".o-mail-Composer-input", "hee"); + assert.containsNone($, ".o-mail-Composer-suggestion:contains(help)"); + // Simulate pressing backspace + await afterNextRender(() => { + const textarea = document.querySelector(".o-mail-Composer-input"); + textarea.value = textarea.value.slice(0, -1); + }); + assert.containsOnce($, ".o-mail-Composer-suggestion:contains(help)"); +});