From 85f8fc52b7a51f6c9f27ad12f2dbb42997ef84d2 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 11 Sep 2020 17:23:02 +0200 Subject: [PATCH] ComposerPostPreview: Add scroll anchoring callback This will be needed to replace the `ReplyPlaceholderPreview` component. --- js/src/forum/components/ComposerPostPreview.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/src/forum/components/ComposerPostPreview.js b/js/src/forum/components/ComposerPostPreview.js index 8c7a3c5c4..2be2b4dc6 100644 --- a/js/src/forum/components/ComposerPostPreview.js +++ b/js/src/forum/components/ComposerPostPreview.js @@ -12,10 +12,12 @@ import Component from '../../common/Component'; * * - `composer` The state of the composer controlling this preview. * - `className` A CSS class for the element surrounding the preview. + * - `surround` A callback that can execute code before and after re-render, e.g. for scroll anchoring. */ export default class ComposerPostPreview extends Component { static initAttrs(attrs) { attrs.className = attrs.className || ''; + attrs.surround = attrs.surround || ((preview) => preview()); } view() { @@ -39,7 +41,7 @@ export default class ComposerPostPreview extends Component { preview = content; - s9e.TextFormatter.preview(preview || '', vnode.dom); + this.attrs.surround(() => s9e.TextFormatter.preview(preview || '', vnode.dom)); }; updatePreview();