我将RichText API用于自定义块:
<RichText
tagName="a"
className="button"
placeholder={ __( 'Button text...' ) }
value={ buttonText }
onChange={ ( value ) => setAttributes( { buttonText: value } ) }
/>我使用a作为标记名,因为我希望元素是一个链接,但我不知道如何添加一个URL。可以添加一个href属性吗?将href="some URL"添加到RichText不起作用。我查看了文档,并在谷歌上搜索了一下,但找不到任何指导。
发布于 2018-09-17 07:37:51
请粘贴完整的代码,根据官方古腾堡按钮块。你需要有更多的块属性用于按钮链接,文本-
https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/button/index.js
<RichText.Content
tagName="a"
className={ linkClass }
href={ url }
title={ title }
style={ buttonStyle }
value={ text }
/>如您所见,有一个URL、Title & Text属性。
url: {
type: 'string',
source: 'attribute',
selector: 'a',
attribute: 'href',
},
title: {
type: 'string',
source: 'attribute',
selector: 'a',
attribute: 'title',
},
text: {
type: 'array',
source: 'children',
selector: 'a',
},https://wordpress.stackexchange.com/questions/313664
复制相似问题