5

Custom Inline Toolbar, as prescribed in their documentation is not working as expected. It keeps showing the default Inline Toolbar, even though custom buttons are added.

My code goes below.

import Editor from "draft-js-plugins-editor";
import createInlineToolbarPlugin from "draft-js-inline-toolbar-plugin";
import { ItalicButton, BoldButton, UnderlineButton } from "draft-js-buttons";
import "draft-js-inline-toolbar-plugin/lib/plugin.css";
import createLinkPlugin from "draft-js-anchor-plugin";

const linkPlugin = createLinkPlugin(); // Adding link button.

const inlineToolbarPlugin = createInlineToolbarPlugin(
    BoldButton,
    ItalicButton,
    UnderlineButton,
    linkPlugin.LinkButton
);

const { InlineToolbar } = inlineToolbarPlugin;

<Editor
    editorState={this.state.editorState}
    onChange={this.onChange}
    plugins={plugins}
    ref={element => {
        this.editor = element;
    }}
/>
<InlineToolbar />

Versions as follows.

  • "react": "^16.4.1"
  • draft-js-plugins-editor": "^2.1.1"

Thanks in advance.

1 Answer 1

6

Firstly, in the example they actually pass an object as the parameter, like so:

const inlineToolbarPlugin = createInlineToolbarPlugin({
  structure: [
    BoldButton,
    ItalicButton,
    UnderlineButton,
    CodeButton,
    Separator,
    HeadlinesButton,
    UnorderedListButton,
    OrderedListButton,
    BlockquoteButton,
    CodeBlockButton
  ]
});

However, since the time the documentation was written, the plugin API has changed to now take custom buttons as children, meaning that in order to add custom buttons, you should use the following code:

<InlineToolbar>
    {
        externalProps => (
            <>
                <ItalicButton {...externalProps} />
                <BoldButton {...externalProps} />
                <UnderlineButton {...externalProps} />
                <UnorderedListButton {...externalProps} />
                <HeadlineOneButton {...externalProps} />
                <HeadlineTwoButton {...externalProps} />
                <HeadlineThreeButton {...externalProps} />
                <OrderedListButton {...externalProps} />
            </>
        )
    }
</InlineToolbar>
4
  • 1
    Excellent. May I know from where you find this documentation? I am eager to know. Oct 21, 2018 at 8:06
  • @BalasubramaniM Sorry for the late reply! I just found it by exploring the code, the repo, and the documentation of the other plugins :) Oct 23, 2018 at 18:59
  • I think the docs @GarethJones mentioned, are these ones: github.com/draft-js-plugins/draft-js-plugins/blob/… Altough, I have a lot of troubles to create customise it and style it at the same time, following the same exact stories. Anyone with the same problem?
    – JC Garcia
    Nov 19, 2018 at 9:17
  • I must admit, the documentation is terrible and the general community support is not there also. I think I will give up with it. Jul 17, 2022 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.