diff --git a/addons/mail/static/tests/emoji/emoji_tests.js b/addons/mail/static/tests/emoji/emoji_tests.js index 9e1ecaaed24..7654d035876 100644 --- a/addons/mail/static/tests/emoji/emoji_tests.js +++ b/addons/mail/static/tests/emoji/emoji_tests.js @@ -37,6 +37,18 @@ QUnit.test("search emoji from keywords with special regex character", async () = await contains(".o-Emoji", { text: "🆎" }); }); +QUnit.test("updating search emoji should scroll top", async (assert) => { + const pyEnv = await startServer(); + const channelId = pyEnv["discuss.channel"].create({ name: "" }); + const { openDiscuss } = await start(); + await openDiscuss(channelId); + await click("button[aria-label='Emojis']"); + await contains(".o-EmojiPicker-content", { scroll: 0 }); + await scroll(".o-EmojiPicker-content", 150); + await insertText("input[placeholder='Search for an emoji']", "m"); + await contains(".o-EmojiPicker-content", { scroll: 0 }); +}); + QUnit.test("Press Escape in emoji picker closes the emoji picker", async () => { const pyEnv = await startServer(); const channelId = pyEnv["discuss.channel"].create({ name: "" }); diff --git a/addons/web/static/src/core/emoji_picker/emoji_picker.js b/addons/web/static/src/core/emoji_picker/emoji_picker.js index dedd238d430..f9d3de548a7 100644 --- a/addons/web/static/src/core/emoji_picker/emoji_picker.js +++ b/addons/web/static/src/core/emoji_picker/emoji_picker.js @@ -131,6 +131,7 @@ export class EmojiPicker extends Component { categories = null; emojis = null; shouldScrollElem = null; + lastSearchStr; setup() { this.inputRef = useRef("input"); @@ -199,10 +200,15 @@ export class EmojiPicker extends Component { useEffect( () => { if (this.state.searchStr) { + this.gridRef.el.scrollTop = 0; this.state.categoryId = null; } else { + if (this.lastSearchStr) { + this.gridRef.el.scrollTop = 0; + } this.highlightActiveCategory(); } + this.lastSearchStr = this.state.searchStr; }, () => [this.state.searchStr] );