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

Remove div.codex-editor__redactor click listener #1051

Closed
2277Dhruv opened this issue Mar 6, 2020 · 7 comments · Fixed by #1252
Closed

Remove div.codex-editor__redactor click listener #1051

2277Dhruv opened this issue Mar 6, 2020 · 7 comments · Fixed by #1252
Labels
refactoring Issue for code improvements

Comments

@2277Dhruv
Copy link

I have some components that I built using React inside Editor JS and everything's working smoothly except for the fact that the div.codex-editor__redactor has a click listener, so the onClick for the div holding my React component is not registering.

I can remove the listener on chrome, but that's not going to be a "universal" browser solution. So, is there a way to remove this listener for all browsers?

Thanks, I really appreciate this! I love Editor JS!!!

@2277Dhruv
Copy link
Author

Or even just let the click propagate

@hata6502
Copy link
Contributor

May be related to #1020

@gohabereg gohabereg added the refactoring Issue for code improvements label Mar 15, 2020
@allankikkas
Copy link

Additional info: some frameworks like React bind most of its syntetic or native events to document for performance and other reasons (single event handler provides flexibility and single dom node traversing is slow). So if you kill of event propagation to document, then this click event never reaches document and framework events do not trigger.

@natterstefan
Copy link
Contributor

natterstefan commented Mar 17, 2020

This is a duplicate of #946, isn' it @gohabereg?

FTR: this might be related to this issue and provides a (temporary) solution: #946 (comment).

@allankikkas
Copy link

allankikkas commented Mar 17, 2020

@natterstefan ref passing is bad practice for react components, please do not use this. Better temporary solution would be setting section for tool wrapper using already known dom node and setting user-select: none; in css to hide visual selection (as this already works when there is a selection set, which may or may not be a bug).

render () { const wrapper = document.createElement('div'); this.api.listeners.on(wrapper, 'click', (e) => { this.api.selection.expandToTag(wrapper); }, false); ReactDOM.render(( <SomeCustomComponent/> ), wrapper); return wrapper; }

@natterstefan
Copy link
Contributor

Hi @aablinov,

I know, the solution was not provided by me and in our app we adjusted it tbh. Thanks for the objection.

Actually, this looks pretty good to me (I just formatted it properly):

  asdf() {
    const wrapper = document.createElement('div')
    this.api.listeners.on(
      wrapper,
      'click',
      e => {
        this.api.selection.expandToTag(wrapper)
      },
      false,
    )
    ReactDOM.render(<SomeCustomComponent />, wrapper)
    return wrapper
  }

Thanks for sharing it with me and others.

@elis
Copy link

elis commented Jul 19, 2020

@2277Dhruv I too have a similar issue and implemented a solution by simply binding the redactor clicks to a new element. Hopefully the pull-request will be merged and this can be used in the official release.

Until then you can install this version: https://github.com/elis/editor.js#d02af95

$ yarn add https://github.com/elis/editor.js#d02af95

works like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Issue for code improvements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants