javascript - Gutenberg RichText
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',
},
- 下个月Win7正式“退休”,数据显示国内近60%电脑用户仍在使用
- 运动类穿戴设备今年迎爆发 繁荣背后的陷阱
- 微软推Surface平板 成硬件合作伙伴竞争对手
- anaconda - Trouble using fiona in conda environment: ImportError: DLL load failed while importing _env - Stack Overflow
- shell - Does the `hash` builtin command in Bash has an `-l` option? - Stack Overflow
- uiviewcontroller - MacCatalyst Scene Frame needs adjustment - Stack Overflow
- c++ - Refactor return type using clang transformer - Stack Overflow
- react native - Top SafeArea on iOS cannot be ignored - Stack Overflow
- How to switch flutter project on Android studio 2021.2.1 from my windows machine to android studio ladybug on my mac through Git
- segmentation fault - PHP-FPM sub-process dead with signal 11 when I submit a edit in MediaWiki - Stack Overflow
- Blender Python Script isn't positioning meshes right from the image - Stack Overflow
- Symfony 7 - Autocomplete form field - Stack Overflow
- c - What happens if you call free() on non allocated memory returned by a function - Stack Overflow
- web - Framer Motion Scrollable - Stack Overflow
- html - CSS "vertical-align: middle" doesn't shrink the height of the parent element of img - Stack Ove
- asp.net - Delete Button does not delete in C# Webforms - Stack Overflow
- Is there showhide functionality for boiler plate content in google docs? - Stack Overflow