Skip to content

Commit

Permalink
Merge pull request #1585 from tomusborne/fix/button-richtext-bug
Browse files Browse the repository at this point in the history
Fix: Bug when using `button` as a `RichText` tag
  • Loading branch information
iansvo authored Dec 10, 2024
2 parents e214575 + 730a6ae commit 2cf88ba
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/blocks/text/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ function EditBlock( props ) {
);
}

// The RichText component can't handle the `<button>` tag for some reason.
// It doesn't allow spaces to be entered, and doesn't allow the user to type if there
// isn't already a value entered. To handle this, we'll render a `<button>` tag instead
// and use a `span` as the RichText component tag.
if ( 'button' === elementTagName ) {
return (
<button
{ ...( withBlockProps && blockProps ) }
>
<RichText
{ ...richTextProps }
tagName={ 'span' }
/>
</button>
);
}

return (
<RichText
{ ...richTextProps }
Expand Down

0 comments on commit 2cf88ba

Please sign in to comment.