From 9e5d4407632bf1a54baf7aac09f4339f7c6b696e Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 13 Sep 2023 14:04:40 +0300 Subject: [PATCH 1/3] Add isLinkTag const to avoid code duplication --- packages/block-library/src/button/edit.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/button/edit.js b/packages/block-library/src/button/edit.js index a6c9c035e5bc1..0c1892c6e4c70 100644 --- a/packages/block-library/src/button/edit.js +++ b/packages/block-library/src/button/edit.js @@ -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(); @@ -220,7 +221,7 @@ function ButtonEdit( props ) { setAttributes( { textAlign: nextAlign } ); } } /> - { ! isURLSet && 'a' === TagName && ( + { ! isURLSet && isLinkTag && ( ) } - { isURLSet && 'a' === TagName && ( + { isURLSet && isLinkTag && ( ) } - { 'a' === TagName && isSelected && ( isEditingURL || isURLSet ) && ( + { isLinkTag && isSelected && ( isEditingURL || isURLSet ) && ( { @@ -279,7 +280,7 @@ function ButtonEdit( props ) { /> - { 'a' === TagName && ( + { isLinkTag && ( Date: Wed, 13 Sep 2023 14:10:05 +0300 Subject: [PATCH 2/3] Add `enum` to the tagName definition in `block.json` --- packages/block-library/src/button/block.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/block-library/src/button/block.json b/packages/block-library/src/button/block.json index 28c72d4d22ab0..eec327b4ca48e 100644 --- a/packages/block-library/src/button/block.json +++ b/packages/block-library/src/button/block.json @@ -11,6 +11,7 @@ "attributes": { "tagName": { "type": "string", + "enum": [ "a", "button" ], "default": "a" }, "type": { From 8457a87d72d5315af26857d325a2d14e352e66e9 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 13 Sep 2023 14:20:45 +0300 Subject: [PATCH 3/3] Add isButtonTag const to avoid code duplication --- packages/block-library/src/button/save.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/button/save.js b/packages/block-library/src/button/save.js index 6403c0e5800e6..a7f286270f8fc 100644 --- a/packages/block-library/src/button/save.js +++ b/packages/block-library/src/button/save.js @@ -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 ); @@ -70,14 +71,14 @@ export default function save( { attributes, className } ) {
);