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

Uh oh: encountered an unexpected token 'export' in node_modulesexpoAppEntry.js

I'm encountering a challenge with my Expo project. While attempting to launch my app using yarn start, I'm running into this error: Android Bundling failed 449ms error: node_modules\expo\AppEntry.js: Unexpected token 'export&apo ...

I encountered a problem with the Javascript toggle menu collapsing feature

I have built a custom toggle menu using Javascript: $(document).ready(function() { $('.toggle').click(function () { if ($(this).hasClass("expanded")) { $(this).next().slideUp("fast"); } else { $(&apos ...

The pseudo-element ::before did not function as expected in the CSS code

I attempted to utilize the ::before element in HTML directly. Below is my code: <ul class="clear toogled" style="height:188pxl"> <li tabindex="0" style="display: block;"> <label for="MAP-IA_1_1_OR_CB_1" aria-label="Filter by product"> :: ...

Custom Vue Basic String Renderer for JSONForms

I'm delving into Vue JSONForms and attempting to develop a basic custom text renderer from scratch. While I am aware of the vue-vanilla package available in JSONForms, I want to grasp the fundamental requirements for creating a custom renderer as I an ...

What strategies can I use to eliminate nested loops while constructing a navigation?

I am working with a JSON file that contains data for a navigation panel consisting of links. A brief snippet of the file is shown below: [ { "category": "Pages", "links": [ { "url": "#", "cap ...

Is it possible to use CSS transitions to animate an absolute positioned element?

I am having trouble getting a CSS transition to work for animating an element's position change. I have tried using the all properties in the transition declaration like in this example: http://jsfiddle.net/yFy5n/3/ However, my goal is to only apply ...

The E.js Template encountered an error with an unexpected token "else"

I am in the process of creating a website quickly using e.js & Express. However, I am encountering some problems when trying to use an if-else statement within e.js tags. The if statement works fine, but as soon as I add an else statement, things start t ...

Restrict the number of labels on Chart.js exclusively for smaller displays

How to Limit the Number of Labels on a Chart.js Line Chart I am looking for a way to decrease the number of labels on my line chart only when it is viewed on a small device. The solution provided in the previous post suggests using the following code: xAx ...

Encountering an issue with Masonry's container.append that is causing an Uncaught TypeError: Object does not possess the filter method

I have implemented infinite scroll on my website to display images. The images are arranged using a tool called masonry. Initially, I only load 10 images into the #container div when the page loads. These images are aligned perfectly with no errors in the ...

Discovering old (potentially neglected) npm dependencies: strategies for locating outdated packages

I am aware of the npm outdated command, which shows out-of-date dependencies only if a new version has been published. However, in certain cases (such as abandoned projects), there may not be a new version released and the package could still be considere ...

Having trouble displaying Json data on an HTML page?

I am trying to incorporate a local JSON file into an HTML page using JavaScript. I have successfully loaded the data from the JSON file into the console, but I'm encountering issues when trying to display it on the HTML page. Could someone please revi ...

What could be causing the props in the Child component to return as undefined?

I am encountering an issue with passing props from the Parent component to the Child component in React. Despite my efforts, every prop I try to pass is returning as undefined based on the console log. Any insights into why this might be happening would be ...

Struggling to link variables and functions to an angularJS controller

When using the $scope object to bind functions and variables, and making changes accordingly in HTML, the code works fine. But when using a different object, it doesn't work as expected. Here is an example of a working code snippet: ...

Are memory leaks a common issue with Angular directives?

Using a simple html file to replicate a memory leak: <!doctype html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.min.js"></script> <script> va ...

Incorrect Tooltip DisplayWhat could be causing the issue with

I am facing an issue when trying to add a tooltip to a glyphicon within a tile. It doesn't seem to work correctly when it should. However, placing the tooltip outside of the tile works fine. I'm quite perplexed and would greatly appreciate any as ...

Encountered a Truffle Unbox Error when trying to unbox with Truffle and React

When attempting to use truffle unbox react, I encounter an issue during the set up process: Preparing to download √ Preparing to download - Downloading √ Downloading - Cleaning up temporary files √ Cleaning up temporary files ...

A step-by-step guide to integrating npm python-shell in a React JS application

I am looking to execute and showcase some simple python code using the python-shell package. Can the package be used with react js? Below is a code sandbox where I have included a sample script "x=1+1;print(x)". Is there a method to run this script when a ...

Is there a way to transform the searchParams function into an object? Changing from URLSearchParams { 'title' => '1' } to { title : 1 }

Is there a way to convert the searchParams function into an object, transforming from URLSearchParams { 'title' => '1' } to { title : 1 }? I need this conversion to be applied for all values in the URLSearchParams, not just one. Cur ...

Performing a $lookup operation across various collections for a nested output

I have multiple collections and I've utilized the separate collection & foreign key approach. Now, I'm looking to combine these collections to create nested collections. Take a look at my collection schemas: const SurveySchema = new Schema({ _id ...

What is the best way to include Google Calendar in a div container while ensuring it is responsive?

I'm currently working on the layout of a website that features a slideshow of images at the top, followed by an embedded Google Calendar. I've encountered an issue with the responsiveness of the Google Calendar within its designated div container ...