Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-root editor - conditional rendering of toolbar prevents display #434

Closed
lnmp4000 opened this issue Dec 5, 2023 · 1 comment · Fixed by #440
Closed

Multi-root editor - conditional rendering of toolbar prevents display #434

lnmp4000 opened this issue Dec 5, 2023 · 1 comment · Fixed by #440
Assignees
Labels
squad:collaboration Issue to be handled by the Collaboration team. type:bug
Milestone

Comments

@lnmp4000
Copy link

lnmp4000 commented Dec 5, 2023

If you apply any sort of conditional rendering to the toolbarElement from the useMultiRootEditor hook, the toolbar will fail to display if it is not immediately mounted, or mounted later

e.g.

import React, { useState } from "react";
import MultiRootEditor from "@ckeditor/ckeditor5-build-multi-root";
import { useMultiRootEditor } from "@ckeditor/ckeditor5-react";

export default function MultiRootEditorDemo(props) {
  const [showToolbar, setShowToolbar] = useState(false);

  const editorProps = {
    editor: MultiRootEditor,
    data: props.data
  };

  const { toolbarElement, editableElements } = useMultiRootEditor(editorProps);

  return (
    <>
      <div>
        <button onClick={() => setShowToolbar(!showToolbar)}>
          Show Toolbar
        </button>
      </div>
      <hr />

      <div>
        <div>ShowToolbar is set to: {JSON.stringify(showToolbar)} </div>
        <div>{showToolbar && toolbarElement}</div>
        {editableElements}
      </div>
    </>
  );
}

In the above example, using the button to set showToolbar to true, still doesn't let the toolbar render.
If showToolbar is initially set to true then the toolbar is rendered, but if the button is clicked to flip showToolbar to false it is impossible to render the toolbar again.

https://codesandbox.io/p/sandbox/condescending-shape-ks59rp?file=%2Fsrc%2Findex.js

@DawidKossowski DawidKossowski self-assigned this Dec 7, 2023
@DawidKossowski
Copy link
Contributor

@lnmp4000, thank you for reporting this issue. We will address and release a fix in January.

In the meantime, you can use a workaround by adding a CSS class to hide the toolbar.

@DawidKossowski DawidKossowski added type:bug squad:collaboration Issue to be handled by the Collaboration team. labels Dec 12, 2023
scofalik added a commit that referenced this issue Jan 19, 2024
Fix: The toolbar element will be rendered correctly after changing the reference (in the rerendering process). Closes #434.
@CKEditorBot CKEditorBot added this to the iteration 71 milestone Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
squad:collaboration Issue to be handled by the Collaboration team. type:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants