question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[static-toolbar-plugin] call onChange after clicking a button

See original GitHub issue

Hello,

I am using the code from the custom static toolbar example and when I click any of the draft-js-buttons or even using the key commands, the state of my editor doesn’t get updated until I actually write something.

How could I update the state of the editor after enabling any of the rich text functions? I can’t find any doc on that.

Thank you

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
Wgilcommented, Jan 11, 2019

@vrinceanuv Dude not pretty sure what was wrong there.

Anyway here are a couple of methods, hope this can can be helpful.

onChange = editorState => {
    const oldContent = stateToHTML(this.state.editorState.getCurrentContent());
    const newContent = stateToHTML(editorState.getCurrentContent());
    this.setState({
      editorState
    });

    // onChange is called on mounting phase and I think that's an unwanted behavior
    // for our current use case. This way we make sure that something really changed
    // to then call our onChange prop
    if (oldContent !== newContent) {
      this.props.onChange(editorState);
    }
  };

handleKeyCommand = command => {
    const { editorState } = this.state;
    const newState = RichUtils.handleKeyCommand(editorState, command);
    if (newState) {
      this.onChange(newState);
      return "handled";
    }
    return "not-handled";
  };

Tell me how you solved it!

1reaction
vrinceanuvcommented, Jan 9, 2019

@Wgil Having the same issue, but my onChange works as expected. What have you had there? Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

draftjs - custom button in inline toolbar that calls custom function
This way, I have managed to get a Button that shows up in the inline toolbar. But when I clicked on that button,...
Read more >
Toolbar - DraftJS Plugins - High quality plugins with great UX
Simple Static Toolbar Example. The toolbar above the editor can be used for formatting text, as in conventional static editors …
Read more >
onChange event. Get an event when the content changes
onChange event. Get an event when the content changes · 1. Extract the contents of the file into the "plugins" folder of CKEditor....
Read more >
How to Add Call to Action Buttons in WordPress (without Code)
Add button in WordPress with WordPress button shortcode plugin. ... Go to Settings » WP Call Button and click on the Static Call...
Read more >
API - Quill Rich Text Editor
For example, when a user clicks on the toolbar, technically the toolbar module calls a Quill API to effect the change. But source...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found