[英]React Grid Layout - Update Tinymce Editor height after first Init
I have a React Component that renders an instance of tinymce editor.The goal is to resize the editor's height dynamically after it has been initialized. 我有一个React组件,可以渲染tinymce编辑器的实例。目标是在初始化后动态调整编辑器的高度。 I am using "React Grid Layout" package to resize the component. 我正在使用“反应网格布局”包来调整组件的大小。
2 Questions: 1. Where can I look up for the change in height of the editor's parent within the react component.In which lifecycle? 2个问题:1.在哪里可以找到编辑组件父对象的高度变化?在哪个生命周期中? 2. Where should Update the editor configuration for its height? 2.应该在哪里更新编辑器配置的高度? Within the init method? 在init方法内?
render(){
<div id="wrapper">
<textArea id="tinymceSelector"></textArea>
</div>
}
Part of my solution is to determine the parent's height like this: 我的解决方案的一部分是确定父母的身高,如下所示:
let parentHeight = document.getElementById('wrapper').clientHeight
If there is any difference before and after resizing with React Grid Layout this parent Height will show the difference in size. 如果在使用React Grid Layout调整大小前后存在任何差异,则此父高度将显示大小差异。
After I have found the height and determine the height change (but where? that is my question 1). 找到高度并确定高度变化后(但是在哪里?这是我的问题1)。 I would update the tinymce configuration with: 我将使用以下命令更新tinymce配置:
editorinstance.theme.resizeTo (width, height);
Thank you!! 谢谢!!
The implemented solution was: 实施的解决方案是:
On first render, I initialize the tinymce editor as follows: 在第一次渲染时,我按如下方式初始化tinymce编辑器:
I calculate the initial height at which the editor should be rendered based on #wrapper
height. 我根据#wrapper
高度计算应显示编辑器的初始高度。
I set the for the #wrapper
's height in a variable called this._wrapperHeight
. 我设置为#wrapper
的身高在一个名为变量this._wrapperHeight
。
Instead of setting the editor's height to the same height as the #wrapper
, I adjust it to be only 70% of the total value. 我没有将编辑器的高度设置为与#wrapper
相同的高度,而是将其调整为仅占总值的70%。 This prevents scrollbars. 这样可以防止滚动条。 (I must say, I would like a different implementation to this because when I resize it to be too small the scrollbars are persistent) (我必须说,我想要一个不同的实现,因为当我将其调整得太小时,滚动条将保持不变)
this._editorHeight = this._wrapperHeight * 0.7; this._editorHeight = this._wrapperHeight * 0.7;
During init, the I also had to include the plugin autoresize
in the editor's configuration and also set the autoresize_min_height=this._editorHeight
在初始化期间,我还必须将插件autoresize
在编辑器的配置中,还必须设置autoresize_min_height=this._editorHeight
After initialization has been accomplished, updating the height dynamically was achieved as follows: 完成初始化之后,可以动态更新高度,如下所示:
In componentWillReceiveProps
I calculate the #wrapper
's height again. 在componentWillReceiveProps
我再次计算#wrapper
的高度。
Evaluate the old wrapper's height vs the new one 评估旧包装纸的高度与新包装纸的高度
If they are different then: set the new height tinymce.get(this.props.renderId).theme.resizeTo(this._editorWidth, this._editorHeight);
如果它们不同,则:设置新的高度tinymce.get(this.props.renderId).theme.resizeTo(this._editorWidth, this._editorHeight);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.