Tips on expanding the dimensions of CKEditor React component using Material UI react

I have integrated CKEditor React Component into my project from the following link: . I am using this component multiple times across different folders within my project.

import React, { Component } from "react";
import { CKEditor } from "@ckeditor/ckeditor5-react";
import ClassicEditor from "@ckeditor/ckeditor5-build-classic";
import "./RichTextEditor.css";

const RichTextEditor = () => {
  return (
    <div>
      <CKEditor 
        editor={ClassicEditor}
        data="<p>Enter your brand description here...</p>"
        onReady={(editor) => {
          // You can store the "editor" and use when it is needed.
          console.log("Editor is ready to use!", editor);
        }}
        onChange={(event, editor) => {
          const data = editor.getData();
          console.log({ event, editor, data });
        }}
        onBlur={(event, editor) => {
          console.log("Blur.", editor);
        }}
        onFocus={(event, editor) => {
          console.log("Focus.", editor);
        }}
      />
    </div>
  );
};

export default RichTextEditor;

In one instance of usage in folder A, I adjusted the height of the editor by modifying the CSS file as shown below:

RichTextEditor.css (in folder A)

.ck-editor__editable {
  min-height: 100px;
}

Now, I need to reuse the same component in a different folder B with a different height requirement. I want to maintain reusability of the component without duplicating code or creating separate CSS files for each folder. However, I am unsure of how to customize the styling of CKEditor components using Material UI's makeStyles feature. Can someone guide me on how I can achieve this flexibility in setting different heights for the CKEditor component while leveraging Material UI? Thank you!

Answer №1

I recently tackled the same issue myself. While it's possible to adjust the minimum height of the CKEditor component like this:

onReady={(editor) => {
   editor.ui.view.editable.element.style.minHeight = "500px";
}}

as demonstrated in: How to set the height of CKEditor 5 (Classic Editor)

You'll also need to apply similar adjustments for onFocus and onBlur events. The solution I tried for onBlur was overridden by CKEditor, causing it to shrink. Although a temporary workaround could involve adding an unsightly delay, it thankfully wasn't necessary.

Instead, a cleaner approach might be:

A)

import { makeStyles } from '@material-ui/core/styles';

B)

const useStyles = makeStyles((theme) => ({
    richTextEditor: {
        "& .ck-editor__main > .ck-editor__editable": {
            minHeight: "100px"
        }
    }
}));

Then within the component:

C) const classes = useStyles();

D)

<div className={classes.richTextEditor}>
    <CKEditor .../>
</div>

While there may be more optimal approaches, this method appears sufficiently neat and effective.

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

Troubleshooting Cors proxy problems in the server.js file (using React, Express, and SQL)

I set up a basic fullstack website using mssql and express. Initially, the get routes were functioning properly but they stopped working after I added the post route. It seems like I'm encountering a cors error which is: Proxy error: Could not proxy ...

Change the filter items operator to "OR" from "AND"

Currently tackling the XGrid project, I'm faced with the task of filtering rows based on checkboxes selected on my page. I've been attempting to pass items into the filterItems prop to create multiple filters, but I'm struggling to figure ou ...

Creating a multi-dimensional array using information from a database

I have a unique challenge where I am utilizing a template that generates a menu with a specific structure. In my database, I have various menus stored and I've successfully retrieved them. However, the issue arises when I need to figure out a way to d ...

"The Material UI date picker is encountering an issue with the error prop, which is being evaluated

I have developed a date picker that utilizes the Jalali calendar. While attempting to pass error checking using the error prop in the following code: <LocalizationProvider dateAdapter={AdapterJalali}> <MobileDatePicker label={lab ...

How can I retrieve the HTML content of a ReactJS rectangle element saved in an array?

Within a loop, I am creating rectangle elements and adding them to an array: rectangles = []; render: function() { for (var i = 0 ; i < 10; i++) { rectangles.push (<Rectangle height={this.props.afm} width={this.props.afm} x={xpos} y={ypos} va ...

How to Re-render a Child Component in React.js Without Rendering the Parent Component

Currently, I am diving into the world of React js and facing a challenge. I need to update one of the child components from its parent component without rerendering the entire parent component. Let me share how I tackled this issue in my code snippet below ...

Hide the menu when a user clicks on any of its options

On a next.js website, there is a hidden panel that slides out from the edge when a button is clicked. Inside the panel, there is a menu. The panel and the menu are separate components. The goal is to have the panel open and close when the button is clicked ...

Sending data between components in Next.js layout.tsx

Trying to figure out how to pass properties between a page and a layout in Next.js has got me scratching my head. The situation I'm facing is as follows: I've got a standard Material UI stepper component (you can find it here: link) in my layou ...

Adjust the circle's background color according to the numeric value in NextJS

I am trying to customize the background circle color depending on the {id} parameter. I am currently implementing this feature in my project using NextJs and Tailwind CSS for styling. <div className="rounded-full bg-fixed h-8 w-8" style={{c ...

Troubles with CSS in MUI Component Integration

How can I successfully implement a vertical timeline using Material UI in React? I've set it up, but the CSS isn't functioning as expected. Is there an error in my implementation? List of Dependencies: "@emotion/react": "^11.11.1& ...

Encountering a Typescript issue when trying to access props.classes in conjunction with material-ui, react-router-dom

I could really use some help with integrating material-ui's theming with react-router-dom in a Typescript environment. I'm running into an issue where when trying to access classes.root in the render() method, I keep getting a TypeError saying &a ...

The autonomous APIService requires access to either redux or the NextJS context in order to retrieve the token

Within my NextJS Application, I have a dedicated APIService.js file that serves various purposes, with the primary function being to set the BASE_URL and handle user authentication (checking for a token in either cookies or headers and dispatching it into ...

The initial value in useEffect is not being updated by useState

I am currently implementing a like feature for my web application. The issue lies in the fact that my setLike function is not updating the state even after using setLike(!like). I verified this by adding console.log() statements before and after the setLik ...

Using a CSS gradient with a variable in React.js - A guide to implementation

Looking to incorporate the following CSS property into the Navlink component. In the CSS file, the property is usually written like this using gradient. .ele { background-image: linear-gradient(45deg, #808080 25%, transparent 25%), li ...

using flexbox in react does not automatically resize

I am attempting to create a layout where the screen is split into two sections - one green block taking up 1/4 of the screen and one yellow block taking up 3/4 of the screen using react.js. However, when I tried implementing the code below, both blocks end ...

Is there a solution for React Components child component rendering twice?

When I click on the Update Key button, Child1 component renders every time. How can I resolve this issue? Note: I have created three components - one parent component and two child components. When I click on the parent component's button to update th ...

storing information in localStorage using react-big-calendar

Incorporating react-big-calendar into my project, I encountered a problem where the events in the calendar would disappear upon page refresh despite saving them in localStorage. I had planned to store the events using localStorage and retrieve them later, ...

Enhancing User Interfaces with React and CSS Styling

I need to incorporate two unique React components on my webpage: Component1 and Component2. Code for Page1: <Component1/> <Component2/> While the individual components will have their own CSS files for styling, I also have a page1.css file f ...

Navigate back to the home page in Next.js and automatically scroll to the previous position you were at on the page

I'm currently working on a next.js app and I'm trying to implement a "back to start" link with specific behavior: The user starts on the main page and scrolls down. When navigating to a subpage, they should find the "back to start" link. If the ...

method for sorting labels in Select element in ReactJS

Hey there, I'm facing an issue with the code snippet available here. I would really appreciate it if you could assist me in resolving this problem. This is the code: import React from "react"; import { Select } from "antd" ...