Adjusting the height of the Tinymce Editor in React Grid Layout after the initial initialization

I am facing a challenge with my React Component that displays a tinymce editor. The task is to dynamically adjust the height of the editor after it has been initialized. To achieve this, I am utilizing the "React Grid Layout" package for resizing the component.

I have 2 questions in mind: 1. In which lifecycle method can I check for changes in the parent's height where the editor is rendered? 2. Where should I update the editor's configuration to set its height? Should it be within the init method?

render(){
  <div id="wrapper">
      <textArea id="tinymceSelector"></textArea>
  </div>
}

One aspect of my proposed solution involves determining the height of the parent element as follows:

let parentHeight = document.getElementById('wrapper').clientHeight 

If there is a disparity in the parent height before and after resizing using React Grid Layout, this value will indicate the difference in size.

Once I have identified the height change (which brings me back to question 1), I plan to update the tinymce configuration with:

editorinstance.theme.resizeTo(width, height);

Any insights or suggestions would be greatly appreciated. Thank you!

Answer №1

The solution that was put into action:

When the page is first loaded, I initialize the tinymce editor in the following manner:

  1. I determine the initial height at which the editor should appear based on the height of #wrapper.

  2. I save this height value for #wrapper in a variable named this._wrapperHeight.

  3. Instead of setting the editor's height to match that of #wrapper, I adjust it to be 70% of the total height. This adjustment helps avoid scrollbars. (I must admit, I would prefer a different approach because persistent scrollbars are an issue when the height is resized too small)

    this._editorHeight = this._wrapperHeight * 0.7;

  4. As part of the initialization process, I also had to include the plugin autoresize in the editor's settings and specify

    autoresize_min_height=this._editorHeight

Once the initialization is completed, the dynamic height updating was achieved as follows:

  1. In the componentWillReceiveProps function, I recalculate the height of #wrapper.

  2. Compare the old height of the wrapper to the new one.

  3. If they differ, then: set the new height using

    tinymce.get(this.props.renderId).theme.resizeTo(this._editorWidth, this._editorHeight);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implementing jQuery form validation including checking for the strength of the password

My understanding of jQuery was quite basic until I began working on jQuery form validation with password strength check. I successfully completed the password strength check portion, but now I am unsure of how to enable the submit button once the condition ...

Sending an image file using AJAX and jQuery

I am currently using Mustache JS to generate a template called 'addUser1' for display purposes. However, when I execute this code, only the image location is being sent to the server, not the actual image itself. What could be causing this issue? ...

Passing data using the router.push method in 'next/navigation' is a quick and efficient way to transfer information between

Is there a way to pass data between routes using the router.push method in the useRouter() API from next/navigation? Additionally, are there any techniques for performing URL masking in the router.push method from next/navigation like we could do with nex ...

Prevent ui-select from being highlighted when clicked

here's a dilemma : (all in angular 1) I'm using a ui-select like this : https://i.stack.imgur.com/RzH2u.png Here's the code snippet : <div class="formZone-group"> <div class="mandatory-fl"> <div class="man ...

Tips for effectively combining the map and find functions in Typescript

I am attempting to generate an array of strings with a length greater than zero. let sampleArray2:string[] = ["hello","world","angular","typescript"]; let subArray:string[] = sampleArray2 .map(() => sampleArray2 .find(val => val.length & ...

Enhancing Kendo Grid with Checkbox Columns

I am facing a situation with my kendo grid where I need to insert two checkbox columns in addition to the existing set of columns. <script id="sectionPage" type="text/kendo-tmpl"> @(Html.Kendo().Grid<SectionPageModel>() .Na ...

Express JS causing NodeJS error | "Issue with setting headers: Unable to set headers after they have been sent to the client"

As I embark on my journey to learn the fundamentals of API development, I am following a tutorial on YouTube by Ania Kubow. The tutorial utilizes three JavaScript libraries: ExpressJS, Cheerio, and Axios. While I have been able to grasp the concepts being ...

Show concealed content for individuals who do not have javascript enabled

One of the challenges I faced was creating a form with a hidden div section that only appears when a specific element is selected from a list. To achieve this, I utilized CSS to set the display property of the div to 'none' and then used jQuery t ...

Guide to programmatically configuring meta title, description, and image in a Vue.js project with the help of Vue Unhead and Vue Meta

I'm currently developing a Vue.js project where I need to dynamically set the meta title, description, and image based on data fetched from an API. To handle the meta tags, I am utilizing Vue Vue Unhead along with Vue Meta. Below is a snippet of the r ...

Using the ESNEXT, Gutenberg provides a way to incorporate repeater blocks that

If you're like me, trying to create your own custom Gutenberg repeater block with a text and link input field can be quite challenging. I've spent hours looking at ES5 examples like this and this, but still feel stuck. I'm reaching out for ...

Conceal the .dropdown-backdrop from bootstrap using solely CSS styling techniques

Is there a way to hide the .dropdown-backdrop element from Bootstrap for a specific dropdown on a webpage using only CSS? I found a solution that involves Javascript, you can view it on JSFiddle here. However, I am hoping to achieve this without relying o ...

Click on the next tab within the ExtJS tab menu

I am looking to deactivate a tab and if it happens to be active, I want the system to automatically switch to the next tab. I attempted myPanel.tab.disable(); if(myPanel.tab.active) myPanel.NextSibling().tab.setActive(); and myPanel.tab.disable(); ...

AngularJS ng-focus does not function properly with iframes

Why isn't ng-focus working with iframe in AngularJS? What am I missing? Take a look at my code: <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script> <iframe src="example.com" tabindex="-1" ng-fo ...

Dealing with promises in ng-if function in AngularJS

When working with AngularJS, I have a scenario where I am using ng-show="isChecked('ID')" in an element to access a $rootScope array that is generated in another controller. Here's my function: $scope.isChecked = function(ID) { c ...

Utilizing JavaScript variables imported from an external library in Next.js: A Guide

I am currently working on a Next.js with Typescript website and I am in the process of adding advertisements. The ad provider has given me instructions to embed this JavaScript code on my site: <script src="//m.servedby-buysellads.com/monetization. ...

Whenever I nest my div tags within another div element in an HTML document

Whenever I try to position a div inside another div using float, I encounter problems. <div id="main"> <div id="anotherDiv"> <h1>Test</h1> </div> </div> Here is the corresponding style sheet: #main{ ba ...

Using localStorage item as query value in socket.io: A step-by-step guide

Goal To authenticate users through a socket.io connection by passing a token from localStorage. Following the instructions in the documentation, I have initialized io() outside of MyComponent and added the token as a query: const token = localStorage.getI ...

Within the materia-ui table, I am facing an issue where clicking the button to expand a row results in all rows expanding. I am seeking a solution to ensure only the selected row expands

When a row is clicked, all rows in the data table expand to show inner data for each row. The issue is that clicking the expand button expands all rows rather than just the selected row. Each time I try to expand one specific row, it ends up expanding mul ...

CSS Sprite Animation Technique

Hello there, I've been attempting to create a simple animation using CSS and a sprite but for some reason it's not working. Can anyone help me figure out what I'm missing? I have created a sample on JS Fiddle. Could someone please explain w ...

Exploring the Functionality of Using Multiple Middlewares in Vue.js 3

For my web app project using vue.js 3 and vue-router, I followed a helpful tutorial on implementing middleware pipelines. The tutorial can be found at: https://blog.logrocket.com/vue-middleware-pipelines/. This tutorial demonstrated creating middleware to ...