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

Button Block: Set proper typography for inner elements #68023

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

shimotmk
Copy link
Contributor

@shimotmk shimotmk commented Dec 16, 2024

What?

The current typography does not work correctly with the given button styles. This fix forces inner elements to inherit the styles.

Fixes #64662
related #64869

Why?

How?

Testing Instructions

  1. Set Twenty Twenty-Four theme
  2. Place Button block
  3. Set the Appearance to Bold, etc.
    You can see that the Appearance has changed on either the editor screen or the front screen.

Testing Instructions for Keyboard

Screenshots or screencast

Before After

Copy link

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core, Gutenberg Plugin.
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

Copy link

github-actions bot commented Dec 16, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: shimotmk <[email protected]>
Co-authored-by: ramonjd <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: talldan <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@@ -301,6 +317,7 @@ function ButtonEdit( props ) {
...colorProps.style,
...spacingProps.style,
...shadowProps.style,
...typographyProps.style,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I think the .wp-block-button__link height of 100% is interfering with the typography setting writing-mode: vertical-rl;

Screenshot 2024-12-17 at 11 07 42 am

I wonder if changing it to auto would break anything else 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If writing-mode is best placed still on the wrapper, we could just change the __experimentalSkipSerialization value for typography to be an array of all the other typography features except writing mode.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! I didn't think of that, thanks!

Copy link
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for wrangling this fix @shimotmk 👍

While reading through the changes I've spotted a few issues and left inline comments for those.

There also looks to be a possible opportunity to clean up the .has-custom-font-size class. It appears that was added to allow the inner element to be forced to inherit the parent font size.

Regarding the e2e failures, there are two issues;

  1. The new deprecation fixture for the v12 button needs to have a Button block as the base block rather than a Buttons block
  2. The v10 fixture has typography styles in it so the final .serialized.html result for the fixture needs to have the typography classes and styles moved to the inner element.

The last point there would be cover by running npm run fixtures:regenerate. Doing so will also leave a few other unrelated fixtures updated due to the fact their attributes have been reordered. Those changes can be discarded for this PR.

The following diff shows an example of how then fixture could be. It isn't suitable for simply committing to this PR as the fixture should cover all the typography styles (with maybe the exception of writing mode as @ramonjd highlighted).

Example diff fixing fixtures
diff --git a/test/integration/fixtures/blocks/core__button__deprecated-v10.serialized.html b/test/integration/fixtures/blocks/core__button__deprecated-v10.serialized.html
index e4c7b89c794..0bebe131629 100644
--- a/test/integration/fixtures/blocks/core__button__deprecated-v10.serialized.html
+++ b/test/integration/fixtures/blocks/core__button__deprecated-v10.serialized.html
@@ -1,3 +1,3 @@
 <!-- wp:button {"fontFamily":"cambria-georgia"} -->
-<div class="wp-block-button has-cambria-georgia-font-family"><a class="wp-block-button__link wp-element-button">My button</a></div>
+<div class="wp-block-button"><a class="wp-block-button__link has-cambria-georgia-font-family wp-element-button">My button</a></div>
 <!-- /wp:button -->
diff --git a/test/integration/fixtures/blocks/core__button__deprecated-v12.html b/test/integration/fixtures/blocks/core__button__deprecated-v12.html
index 03ac733e5c3..355f1c2019d 100644
--- a/test/integration/fixtures/blocks/core__button__deprecated-v12.html
+++ b/test/integration/fixtures/blocks/core__button__deprecated-v12.html
@@ -1,17 +1,3 @@
-<!-- wp:buttons {"align":"wide","layout":{"type":"flex","justifyContent":"center"}} -->
-<div class="wp-block-buttons alignwide"><!-- wp:button {"fontSize":"xx-large"} -->
-<div class="wp-block-button has-custom-font-size has-xx-large-font-size"><a class="wp-block-button__link wp-element-button">My button 1</a></div>
-<!-- /wp:button -->
-
-<!-- wp:button {"style":{"typography":{"fontStyle":"normal","fontWeight":"800"}}} -->
-<div class="wp-block-button" style="font-style:normal;font-weight:800"><a class="wp-block-button__link wp-element-button">My button 2</a></div>
-<!-- /wp:button -->
-
-<!-- wp:button {"style":{"typography":{"letterSpacing":"39px"}}} -->
-<div class="wp-block-button" style="letter-spacing:39px"><a class="wp-block-button__link wp-element-button">My button 3</a></div>
-<!-- /wp:button -->
-
-<!-- wp:button {"tagName":"button","style":{"typography":{"letterSpacing":"39px"}}} -->
-<div class="wp-block-button" style="letter-spacing:39px"><button type="button" class="wp-block-button__link wp-element-button">My button 4</button></div>
-<!-- /wp:button --></div>
-<!-- /wp:buttons -->
+<!-- wp:button {"fontSize":"xx-large","style":{"typography":{"fontStyle":"normal","fontWeight":"800","letterSpacing":"39px"}}} -->
+<div class="wp-block-button has-custom-font-size has-xx-large-font-size" style="font-style:normal;font-weight:800;letter-spacing:39px"><a class="wp-block-button__link wp-element-button">My Button</a></div>
+<!-- /wp:button -->
\ No newline at end of file
diff --git a/test/integration/fixtures/blocks/core__button__deprecated-v12.json b/test/integration/fixtures/blocks/core__button__deprecated-v12.json
index b6cab91f0d5..7fd537b6575 100644
--- a/test/integration/fixtures/blocks/core__button__deprecated-v12.json
+++ b/test/integration/fixtures/blocks/core__button__deprecated-v12.json
@@ -1,72 +1,20 @@
 [
 	{
-		"name": "core/buttons",
+		"name": "core/button",
 		"isValid": true,
 		"attributes": {
-			"align": "wide",
-			"layout": {
-				"type": "flex",
-				"justifyContent": "center"
+			"tagName": "a",
+			"type": "button",
+			"text": "My Button",
+			"fontSize": "xx-large",
+			"style": {
+				"typography": {
+					"fontStyle": "normal",
+					"fontWeight": "800",
+					"letterSpacing": "39px"
+				}
 			}
 		},
-		"innerBlocks": [
-			{
-				"name": "core/button",
-				"isValid": true,
-				"attributes": {
-					"tagName": "a",
-					"type": "button",
-					"text": "My button 1",
-					"fontSize": "xx-large"
-				},
-				"innerBlocks": []
-			},
-			{
-				"name": "core/button",
-				"isValid": true,
-				"attributes": {
-					"tagName": "a",
-					"type": "button",
-					"text": "My button 2",
-					"style": {
-						"typography": {
-							"fontStyle": "normal",
-							"fontWeight": "800"
-						}
-					}
-				},
-				"innerBlocks": []
-			},
-			{
-				"name": "core/button",
-				"isValid": true,
-				"attributes": {
-					"tagName": "a",
-					"type": "button",
-					"text": "My button 3",
-					"style": {
-						"typography": {
-							"letterSpacing": "39px"
-						}
-					}
-				},
-				"innerBlocks": []
-			},
-			{
-				"name": "core/button",
-				"isValid": false,
-				"attributes": {
-					"tagName": "button",
-					"type": "button",
-					"text": "My button 4",
-					"style": {
-						"typography": {
-							"letterSpacing": "39px"
-						}
-					}
-				},
-				"innerBlocks": []
-			}
-		]
+		"innerBlocks": []
 	}
 ]
diff --git a/test/integration/fixtures/blocks/core__button__deprecated-v12.parsed.json b/test/integration/fixtures/blocks/core__button__deprecated-v12.parsed.json
index 466b53ae00e..542817c8428 100644
--- a/test/integration/fixtures/blocks/core__button__deprecated-v12.parsed.json
+++ b/test/integration/fixtures/blocks/core__button__deprecated-v12.parsed.json
@@ -1,84 +1,20 @@
 [
 	{
-		"blockName": "core/buttons",
+		"blockName": "core/button",
 		"attrs": {
-			"align": "wide",
-			"layout": {
-				"type": "flex",
-				"justifyContent": "center"
+			"fontSize": "xx-large",
+			"style": {
+				"typography": {
+					"fontStyle": "normal",
+					"fontWeight": "800",
+					"letterSpacing": "39px"
+				}
 			}
 		},
-		"innerBlocks": [
-			{
-				"blockName": "core/button",
-				"attrs": {
-					"fontSize": "xx-large"
-				},
-				"innerBlocks": [],
-				"innerHTML": "\n<div class=\"wp-block-button has-custom-font-size has-xx-large-font-size\"><a class=\"wp-block-button__link wp-element-button\">My button 1</a></div>\n",
-				"innerContent": [
-					"\n<div class=\"wp-block-button has-custom-font-size has-xx-large-font-size\"><a class=\"wp-block-button__link wp-element-button\">My button 1</a></div>\n"
-				]
-			},
-			{
-				"blockName": "core/button",
-				"attrs": {
-					"style": {
-						"typography": {
-							"fontStyle": "normal",
-							"fontWeight": "800"
-						}
-					}
-				},
-				"innerBlocks": [],
-				"innerHTML": "\n<div class=\"wp-block-button\" style=\"font-style:normal;font-weight:800\"><a class=\"wp-block-button__link wp-element-button\">My button 2</a></div>\n",
-				"innerContent": [
-					"\n<div class=\"wp-block-button\" style=\"font-style:normal;font-weight:800\"><a class=\"wp-block-button__link wp-element-button\">My button 2</a></div>\n"
-				]
-			},
-			{
-				"blockName": "core/button",
-				"attrs": {
-					"style": {
-						"typography": {
-							"letterSpacing": "39px"
-						}
-					}
-				},
-				"innerBlocks": [],
-				"innerHTML": "\n<div class=\"wp-block-button\" style=\"letter-spacing:39px\"><a class=\"wp-block-button__link wp-element-button\">My button 3</a></div>\n",
-				"innerContent": [
-					"\n<div class=\"wp-block-button\" style=\"letter-spacing:39px\"><a class=\"wp-block-button__link wp-element-button\">My button 3</a></div>\n"
-				]
-			},
-			{
-				"blockName": "core/button",
-				"attrs": {
-					"tagName": "button",
-					"style": {
-						"typography": {
-							"letterSpacing": "39px"
-						}
-					}
-				},
-				"innerBlocks": [],
-				"innerHTML": "\n<div class=\"wp-block-button\" style=\"letter-spacing:39px\"><button type=\"button\" class=\"wp-block-button__link wp-element-button\">My button 4</button></div>\n",
-				"innerContent": [
-					"\n<div class=\"wp-block-button\" style=\"letter-spacing:39px\"><button type=\"button\" class=\"wp-block-button__link wp-element-button\">My button 4</button></div>\n"
-				]
-			}
-		],
-		"innerHTML": "\n<div class=\"wp-block-buttons alignwide\">\n\n\n\n\n\n</div>\n",
+		"innerBlocks": [],
+		"innerHTML": "\n<div class=\"wp-block-button has-custom-font-size has-xx-large-font-size\" style=\"font-style:normal;font-weight:800;letter-spacing:39px\"><a class=\"wp-block-button__link wp-element-button\">My Button</a></div>\n",
 		"innerContent": [
-			"\n<div class=\"wp-block-buttons alignwide\">",
-			null,
-			"\n\n",
-			null,
-			"\n\n",
-			null,
-			"\n\n",
-			null,
-			"</div>\n"
+			"\n<div class=\"wp-block-button has-custom-font-size has-xx-large-font-size\" style=\"font-style:normal;font-weight:800;letter-spacing:39px\"><a class=\"wp-block-button__link wp-element-button\">My Button</a></div>\n"
 		]
 	}
 ]
diff --git a/test/integration/fixtures/blocks/core__button__deprecated-v12.serialized.html b/test/integration/fixtures/blocks/core__button__deprecated-v12.serialized.html
index 2df6789245e..1b18b70facc 100644
--- a/test/integration/fixtures/blocks/core__button__deprecated-v12.serialized.html
+++ b/test/integration/fixtures/blocks/core__button__deprecated-v12.serialized.html
@@ -1,17 +1,3 @@
-<!-- wp:buttons {"align":"wide","layout":{"type":"flex","justifyContent":"center"}} -->
-<div class="wp-block-buttons alignwide"><!-- wp:button {"fontSize":"xx-large"} -->
-<div class="wp-block-button has-custom-font-size"><a class="wp-block-button__link has-xx-large-font-size wp-element-button">My button 1</a></div>
+<!-- wp:button {"fontSize":"xx-large","style":{"typography":{"fontStyle":"normal","fontWeight":"800","letterSpacing":"39px"}}} -->
+<div class="wp-block-button has-custom-font-size"><a class="wp-block-button__link has-xx-large-font-size wp-element-button" style="font-style:normal;font-weight:800;letter-spacing:39px">My Button</a></div>
 <!-- /wp:button -->
-
-<!-- wp:button {"style":{"typography":{"fontStyle":"normal","fontWeight":"800"}}} -->
-<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" style="font-style:normal;font-weight:800">My button 2</a></div>
-<!-- /wp:button -->
-
-<!-- wp:button {"style":{"typography":{"letterSpacing":"39px"}}} -->
-<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" style="letter-spacing:39px">My button 3</a></div>
-<!-- /wp:button -->
-
-<!-- wp:button {"tagName":"button","style":{"typography":{"letterSpacing":"39px"}}} -->
-<div class="wp-block-button" style="letter-spacing:39px"><button type="button" class="wp-block-button__link wp-element-button">My button 4</button></div>
-<!-- /wp:button --></div>
-<!-- /wp:buttons -->

I hope that helps 🤞

packages/block-library/src/button/deprecated.js Outdated Show resolved Hide resolved
packages/block-library/src/button/deprecated.js Outdated Show resolved Hide resolved
@@ -301,6 +317,7 @@ function ButtonEdit( props ) {
...colorProps.style,
...spacingProps.style,
...shadowProps.style,
...typographyProps.style,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If writing-mode is best placed still on the wrapper, we could just change the __experimentalSkipSerialization value for typography to be an array of all the other typography features except writing mode.

packages/block-library/src/button/save.js Show resolved Hide resolved
@shimotmk
Copy link
Contributor Author

@ramonjd @aaronrobertshaw
Thanks for reviewing!

I adjusted the attributes and made core__button__deprecated-v12.html into a single button block.

However, the data for the fourth letterSpacing setting in core__button__deprecated-v12.html cannot be migrated.

Why is that?🤔

@aaronrobertshaw
Copy link
Contributor

However, the data for the fourth letterSpacing setting in core__button__deprecated-v12.html cannot be migrated.

I'm not following this comment sorry. It looks fine to me in the lastest commit.

The current e2e failures relate to full post content fixture › core__button__deprecated-v10. As I noted in my review this fixture needing updating. The required change was also in the diff I provided.

After updating the v10 fixture, all the fixture tests pass for me.

Once that is sorted, there's still the issue with writing mode to fix up.

@shimotmk
Copy link
Contributor Author

@aaronrobertshaw
Sorry. I was mistaken. The transition was going well.

@shimotmk
Copy link
Contributor Author

@ramonjd @aaronrobertshaw
I adjusted the writing-mode to add inline styles to the outer div 🙂

@shimotmk
Copy link
Contributor Author

@ramonjd @aaronrobertshaw
Any other things I need to fix?

@aaronrobertshaw
Copy link
Contributor

Any other things I need to fix?

@shimotmk the issue I flagged in my last two reviews still needs fixing.

The current e2e failures relate to full post content fixture › core__button__deprecated-v10. As I noted in my #68023 (review) this fixture needing updating. The required change was also in the diff I provided.

@shimotmk
Copy link
Contributor Author

@aaronrobertshaw
Thanks for the reply

Moved the has-custom-font-size class internally.
And updated test/integration/fixtures/blocks/core__button__deprecated-v10.serialized.html
Is this OK?

@ramonjd
Copy link
Member

ramonjd commented Dec 22, 2024

Thanks for the continued work on this PR @shimotmk 🙇🏻

It looks like the mobile unit tests fails are related to the button block: https://github.com/WordPress/gutenberg/actions/runs/12429816613/job/34704026313?pr=68023#step:6:2906

@shimotmk
Copy link
Contributor Author

@ramonjd
Thanks for the reply
I don't know how to fix the mobile unit.
How do I fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Button Block: Can't set typography
3 participants