admin管理员组文章数量:1435859
I'm using the RichText API for a custom block:
<RichText
tagName="a"
className="button"
placeholder={ __( 'Button text...' ) }
value={ buttonText }
onChange={ ( value ) => setAttributes( { buttonText: value } ) }
/>
I am using a
as the tag name because I want the element to be a link but I'm not sure how to add a URL. Is it possible to add a href
attribute? Adding href="some URL"
to RichText does not work. I looked through the documentation and Googled it but couln't find any guidance.
I'm using the RichText API for a custom block:
<RichText
tagName="a"
className="button"
placeholder={ __( 'Button text...' ) }
value={ buttonText }
onChange={ ( value ) => setAttributes( { buttonText: value } ) }
/>
I am using a
as the tag name because I want the element to be a link but I'm not sure how to add a URL. Is it possible to add a href
attribute? Adding href="some URL"
to RichText does not work. I looked through the documentation and Googled it but couln't find any guidance.
1 Answer
Reset to default 2Please paste the full code, According to official Gutenberg button block. You need to have additional block attributes to use for button link,text -
https://github/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 }
/>
As you can see, there's a URL, Title & Text attributes.
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',
},
本文标签: javascriptGutenberg RichText
版权声明:本文标题:javascript - Gutenberg RichText 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745675201a2669808.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论