Skip to content

React: Clicks on custom plugin with react component are not propagated #946

@natterstefan

Description

@natterstefan

Issue

When rendering a React component in the plugin's render method, clicks on the React element do not trigger it's onClick.

Expected outcome

I can interact with the react component properly (eg. onClick is invoked).

Example

An example codesandbox can be found here: https://codesandbox.io/s/solitary-night-96hzk?fontsize=14. After some more testing it looks like eg. onChange on input elements is not an issue: https://codesandbox.io/s/sweet-resonance-p7xwu.

The React component

import React, { useEffect, useState } from "react";
import ReactDOM from "react-dom";

export default class Custom {
  render() {
    const Button = () => {
      const [count, setCount] = useState(0);

      useEffect(() => console.log("mounting"), []);

      const onClick = e => {
        console.log("clicked"); // << is not triggered
        setCount(prevCount => prevCount + 1);
      };

      return (
        <button onClick={onClick} type="button" style={{ padding: 10 }}>
          Click me [clicked: {count} times]
        </button>
      );
    };

    const container = document.createElement("div");
    ReactDOM.render(<Button />, container);
    return container;
  }

  save(element) {
    console.log(element);
    return {
      text: element.value
    };
  }
}

Environment

  • React: "react": "16.11.0"
  • Editorjs: "@editorjs/editorjs": "2.15.1"

Related Issues/Topics

@gohabereg already posted a gif illustrating the issue:

And I created another one. As soon as you select some text, it works:

Screen Capture on 2019-11-12 at 11-21-23

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions