【发布时间】:2022-01-05 17:17:36
【问题描述】:
我不知道为什么 Gutenberg 将我添加的 BlockControl 渲染 3 次,并且还渲染到其他不是“核心/段落”的组件。 我的代码:
const filter_text_highlight_color = createHigherOrderComponent( (BlockListBlock) => {
return (props) => {
if (props.name === 'core/paragraph') {
const startEditing = () => {
console.log('hello!');
}
return ([
<BlockListBlock {...props} />,
<BlockControls>
<ToolbarButton
name="link"
icon="text-page"
title={ __('Highlight Text') }
onClick={ startEditing }
/>
</BlockControls>,
])
} else {
return (
<BlockListBlock {...props} />
)
}
}
}, 'filter_text_highlight_color'
);
addFilter(
'editor.BlockListBlock',
'bwwpcode/text-highlight-color',
filter_text_highlight_color,
)
我将不胜感激任何关于为什么会发生这种情况以及如何解决它的建议。
【问题讨论】:
标签: wordpress filter block wordpress-gutenberg