Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Followup to #54206 #54419

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/block-library/src/button/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"attributes": {
"tagName": {
"type": "string",
"enum": [ "a", "button" ],
"default": "a"
},
"type": {
Expand Down
9 changes: 5 additions & 4 deletions packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function ButtonEdit( props ) {
const [ isEditingURL, setIsEditingURL ] = useState( false );
const isURLSet = !! url;
const opensInNewTab = linkTarget === '_blank';
const isLinkTag = 'a' === TagName;

function startEditing( event ) {
event.preventDefault();
Expand Down Expand Up @@ -220,7 +221,7 @@ function ButtonEdit( props ) {
setAttributes( { textAlign: nextAlign } );
} }
/>
{ ! isURLSet && 'a' === TagName && (
{ ! isURLSet && isLinkTag && (
<ToolbarButton
name="link"
icon={ link }
Expand All @@ -229,7 +230,7 @@ function ButtonEdit( props ) {
onClick={ startEditing }
/>
) }
{ isURLSet && 'a' === TagName && (
{ isURLSet && isLinkTag && (
<ToolbarButton
name="link"
icon={ linkOff }
Expand All @@ -240,7 +241,7 @@ function ButtonEdit( props ) {
/>
) }
</BlockControls>
{ 'a' === TagName && isSelected && ( isEditingURL || isURLSet ) && (
{ isLinkTag && isSelected && ( isEditingURL || isURLSet ) && (
<Popover
placement="bottom"
onClose={ () => {
Expand Down Expand Up @@ -279,7 +280,7 @@ function ButtonEdit( props ) {
/>
</InspectorControls>
<InspectorControls group="advanced">
{ 'a' === TagName && (
{ isLinkTag && (
<TextControl
__nextHasNoMarginBottom
label={ __( 'Link rel' ) }
Expand Down
9 changes: 5 additions & 4 deletions packages/block-library/src/button/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function save( { attributes, className } ) {
}

const TagName = tagName || 'a';
const isButtonTag = 'button' === TagName;
const buttonType = type || 'button';
const borderProps = getBorderClassesAndStyles( attributes );
const colorProps = getColorClassesAndStyles( attributes );
Expand Down Expand Up @@ -70,14 +71,14 @@ export default function save( { attributes, className } ) {
<div { ...useBlockProps.save( { className: wrapperClasses } ) }>
<RichText.Content
tagName={ TagName }
type={ 'button' === TagName ? buttonType : null }
type={ isButtonTag ? buttonType : null }
className={ buttonClasses }
href={ 'button' === TagName ? null : url }
href={ isButtonTag ? null : url }
title={ title }
style={ buttonStyle }
value={ text }
target={ 'button' === TagName ? null : linkTarget }
rel={ 'button' === TagName ? null : rel }
target={ isButtonTag ? null : linkTarget }
rel={ isButtonTag ? null : rel }
/>
</div>
);
Expand Down
Loading