diff --git a/addons/mail/static/src/components/chatter/chatter.js b/addons/mail/static/src/components/chatter/chatter.js index 42462e930f9..3f6ca7dca41 100644 --- a/addons/mail/static/src/components/chatter/chatter.js +++ b/addons/mail/static/src/components/chatter/chatter.js @@ -47,10 +47,16 @@ class Chatter extends Component { * Reference of the composer. Useful to focus it. */ this._composerRef = useRef('composer'); + /** + * Reference of the scroll Panel (Real scroll element). Useful to pass the Scroll element to + * child component to handle proper scrollable element. + */ + this._scrollPanelRef = useRef('scrollPanel'); /** * Reference of the message list. Useful to trigger the scroll event on it. */ this._threadRef = useRef('thread'); + this.getScrollableElement = this.getScrollableElement.bind(this); } //-------------------------------------------------------------------------- @@ -64,6 +70,16 @@ class Chatter extends Component { return this.env.models['mail.chatter'].get(this.props.chatterLocalId); } + /** + * @returns {Element|undefined} Scrollable Element + */ + getScrollableElement() { + if (!this._scrollPanelRef.el) { + return; + } + return this._scrollPanelRef.el; + } + //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/chatter/chatter.xml b/addons/mail/static/src/components/chatter/chatter.xml index ffb27244471..d9cf20b478e 100644 --- a/addons/mail/static/src/components/chatter/chatter.xml +++ b/addons/mail/static/src/components/chatter/chatter.xml @@ -24,7 +24,7 @@ /> -
+
elRect.bottom || loadMoreRect.bottom < elRect.top; return !isInvisible; } @@ -467,7 +479,7 @@ class MessageList extends Component { */ _scrollToEnd() { const { order } = this._lastRenderedValues(); - this.setScrollTop(order === 'asc' ? this.el.scrollHeight - this.el.clientHeight : 0); + this.setScrollTop(order === 'asc' ? this._getScrollableElement().scrollHeight - this._getScrollableElement().clientHeight : 0); } /** @@ -526,11 +538,11 @@ class MessageList extends Component { threadView, threadViewer, } = this._lastRenderedValues(); - if (!this.el) { + if (!this._getScrollableElement()) { // could be unmounted in the meantime (due to throttled behavior) return; } - const scrollTop = this.el.scrollTop; + const scrollTop = this._getScrollableElement().scrollTop; this.env.messagingBus.trigger('o-component-message-list-scrolled', { orderedMessages, scrollTop, @@ -544,12 +556,12 @@ class MessageList extends Component { // Automatically scroll to new received messages only when the list is // currently fully scrolled. const hasAutoScrollOnMessageReceived = (order === 'asc') - ? scrollTop >= this.el.scrollHeight - this.el.clientHeight - margin + ? scrollTop >= this._getScrollableElement().scrollHeight - this._getScrollableElement().clientHeight - margin : scrollTop <= margin; threadView.update({ hasAutoScrollOnMessageReceived }); } if (threadViewer && threadViewer.exists()) { - threadViewer.saveThreadCacheScrollHeightAsInitial(this.el.scrollHeight, threadCache); + threadViewer.saveThreadCacheScrollHeightAsInitial(this._getScrollableElement().scrollHeight, threadCache); threadViewer.saveThreadCacheScrollPositionsAsInitial(scrollTop, threadCache); } if (!this._isLastScrollProgrammatic && this._isLoadMoreVisible()) { @@ -572,6 +584,14 @@ Object.assign(MessageList, { order: 'asc', }, props: { + /** + * Function returns the exact scrollable element from the parent + * to manage proper scroll heights which affects the load more messages. + */ + getScrollableElement: { + type: Function, + optional: true, + }, hasMessageCheckbox: Boolean, hasSquashCloseMessages: Boolean, haveMessagesMarkAsReadIcon: Boolean, diff --git a/addons/mail/static/src/components/thread_view/thread_view.js b/addons/mail/static/src/components/thread_view/thread_view.js index 30e36ce7399..16dc3e1b165 100644 --- a/addons/mail/static/src/components/thread_view/thread_view.js +++ b/addons/mail/static/src/components/thread_view/thread_view.js @@ -182,6 +182,14 @@ Object.assign(ThreadView, { type: String, validate: prop => ['auto', 'card', 'hover', 'none'].includes(prop), }, + /** + * Function returns the exact scrollable element from the parent + * to manage proper scroll heights which affects the load more messages. + */ + getScrollableElement: { + type: Function, + optional: true, + }, hasComposer: Boolean, hasComposerCurrentPartnerAvatar: { type: Boolean, diff --git a/addons/mail/static/src/components/thread_view/thread_view.xml b/addons/mail/static/src/components/thread_view/thread_view.xml index 16934160298..72e0dcf04d4 100644 --- a/addons/mail/static/src/components/thread_view/thread_view.xml +++ b/addons/mail/static/src/components/thread_view/thread_view.xml @@ -12,6 +12,7 @@