diff --git a/addons/mail/static/src/core/web/chatter.js b/addons/mail/static/src/core/web/chatter.js index b02cfc86457..333bb66850d 100644 --- a/addons/mail/static/src/core/web/chatter.js +++ b/addons/mail/static/src/core/web/chatter.js @@ -99,6 +99,7 @@ export class Chatter extends Component { composerType: false, isAttachmentBoxOpened: this.props.isAttachmentBoxVisibleInitially, jumpThreadPresent: 0, + scrollToAttachments: 0, showActivities: true, showAttachmentLoading: false, /** @type {import("@mail/core/common/thread_model").Thread} */ @@ -174,12 +175,12 @@ export class Chatter extends Component { () => [this.attachments] ); useEffect( - (opened) => { - if (opened) { + () => { + if (this.state.scrollToAttachments > 0) { this.attachmentBox.el.scrollIntoView({ block: "center" }); } }, - () => [this.state.isAttachmentBoxOpened] + () => [this.state.scrollToAttachments] ); useEffect( () => { @@ -394,6 +395,9 @@ export class Chatter extends Component { return; } this.state.isAttachmentBoxOpened = !this.state.isAttachmentBoxOpened; + if (this.state.isAttachmentBoxOpened) { + this.state.scrollToAttachments++; + } } async onClickAttachFile(ev) { diff --git a/addons/mail/static/tests/web/attachment_box_tests.js b/addons/mail/static/tests/web/attachment_box_tests.js index ad41557278d..635d76b39c8 100644 --- a/addons/mail/static/tests/web/attachment_box_tests.js +++ b/addons/mail/static/tests/web/attachment_box_tests.js @@ -155,6 +155,38 @@ QUnit.test("scroll to attachment box when toggling on", async (assert) => { assert.isVisible($(".o-mail-AttachmentBox")); }); +QUnit.test("do not auto-scroll to attachment box when initially open", async (assert) => { + patchUiSize({ size: SIZES.LG }); + const pyEnv = await startServer(); + const partnerId = pyEnv["res.partner"].create({}); + pyEnv["mail.message"].create({ + body: "not empty", + model: "res.partner", + res_id: partnerId, + }); + pyEnv["ir.attachment"].create({ + mimetype: "text/plain", + name: "Blah.txt", + res_id: partnerId, + res_model: "res.partner", + }); + const views = { + "res.partner,false,form": ` +
+ ${``.repeat(100)} +
+ +
+
+ `, + }; + const { openFormView } = await start({ serverData: { views } }); + openFormView("res.partner", partnerId); + await contains(".o-mail-Message"); + // weak test, no guarantee that we waited long enough for the potential scroll to happen + await contains(".o_content", { scroll: 0 }); +}); + QUnit.test("attachment box should order attachments from newest to oldest", async () => { const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({});