draft-js-plugins 中的自定义内联工具栏不起作用
Custom Inline Toolbar in draft-js-plugins is not working
documentation 中规定的自定义内联工具栏未按预期工作。它一直显示默认的内联工具栏,即使添加了自定义按钮也是如此。
我的代码如下。
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 />
版本如下
- "react": "^16.4.1"
- draft-js-plugins-editor": "^2.1.1"
提前致谢。
首先,在示例中,他们实际上传递了一个对象作为参数,如下所示:
const inlineToolbarPlugin = createInlineToolbarPlugin({
structure: [
BoldButton,
ItalicButton,
UnderlineButton,
CodeButton,
Separator,
HeadlinesButton,
UnorderedListButton,
OrderedListButton,
BlockquoteButton,
CodeBlockButton
]
});
但是,自编写文档以来,插件 API 已更改为现在将自定义按钮作为子按钮,这意味着要添加自定义按钮,您应该使用以下代码:
<InlineToolbar>
{
externalProps => (
<>
<ItalicButton {...externalProps} />
<BoldButton {...externalProps} />
<UnderlineButton {...externalProps} />
<UnorderedListButton {...externalProps} />
<HeadlineOneButton {...externalProps} />
<HeadlineTwoButton {...externalProps} />
<HeadlineThreeButton {...externalProps} />
<OrderedListButton {...externalProps} />
</>
)
}
</InlineToolbar>
documentation 中规定的自定义内联工具栏未按预期工作。它一直显示默认的内联工具栏,即使添加了自定义按钮也是如此。
我的代码如下。
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 />
版本如下
- "react": "^16.4.1"
- draft-js-plugins-editor": "^2.1.1"
提前致谢。
首先,在示例中,他们实际上传递了一个对象作为参数,如下所示:
const inlineToolbarPlugin = createInlineToolbarPlugin({
structure: [
BoldButton,
ItalicButton,
UnderlineButton,
CodeButton,
Separator,
HeadlinesButton,
UnorderedListButton,
OrderedListButton,
BlockquoteButton,
CodeBlockButton
]
});
但是,自编写文档以来,插件 API 已更改为现在将自定义按钮作为子按钮,这意味着要添加自定义按钮,您应该使用以下代码:
<InlineToolbar>
{
externalProps => (
<>
<ItalicButton {...externalProps} />
<BoldButton {...externalProps} />
<UnderlineButton {...externalProps} />
<UnorderedListButton {...externalProps} />
<HeadlineOneButton {...externalProps} />
<HeadlineTwoButton {...externalProps} />
<HeadlineThreeButton {...externalProps} />
<OrderedListButton {...externalProps} />
</>
)
}
</InlineToolbar>