Skip to content

Heading Block: Don't rely on the experimental selector anymore#46284

Merged
scruffian merged 2 commits into
trunkfrom
update/heading-block-selector
Dec 6, 2022
Merged

Heading Block: Don't rely on the experimental selector anymore#46284
scruffian merged 2 commits into
trunkfrom
update/heading-block-selector

Conversation

@scruffian
Copy link
Copy Markdown
Contributor

@scruffian scruffian commented Dec 2, 2022

What?

Before we had a class name on the heading block, the only way to target it was using this selector h1,h2,h3,h4,h5,h6. Now we have a class name on the block (#42122), we can remove this __experimentalSelector and revert to the standard selector (.wp-block-heading).

Why?

This gives theme.json more control over what it targets - now heading block settings will only apply to heading blocks, not all heading elements.

How?

Simply remove the __experimentalSelector property.

Testing Instructions

  1. Switch to a block theme
  2. Add this to your theme.json file:
			"core/heading": {
				"color": {
					"background": "red"
				}
			},
  1. Check that the heading block has a red background, but other block that use H* elements do not (for example Post Title).

Testing Instructions for Keyboard

Screenshots or screencast

Screenshot 2022-12-02 at 17 02 49

@WordPress/block-themers

Copy link
Copy Markdown
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

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

This works well for me 👍

Tested using Archeo:

Before After
image image

@scruffian scruffian enabled auto-merge (squash) December 6, 2022 09:55
@scruffian scruffian merged commit ae8714b into trunk Dec 6, 2022
@scruffian scruffian deleted the update/heading-block-selector branch December 6, 2022 10:25
@github-actions github-actions Bot added this to the Gutenberg 14.8 milestone Dec 6, 2022
mpkelly pushed a commit to mpkelly/gutenberg that referenced this pull request Dec 7, 2022
…ress#46284)

* Heading Block: Don't rely on the experimental selector anymore

* update unit test with new selector
@bph bph added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Feb 17, 2023
@bph
Copy link
Copy Markdown
Contributor

bph commented Feb 17, 2023

flagged for Dev notes in 6.2
@scruffian This just needs short blurb added to the Miscellaneous Dev Note. What do you think?
Over the coming days, I will review the comments on the tracking issue and group the PRs accordingly.

@scruffian
Copy link
Copy Markdown
Contributor Author

Dev note

Giving block themes more control over headings

To give themes more fine grained control over styling headings, it is now possible to control heading blocks independently of heading elements. To target all headings themes can target heading elements:

	"styles": {
		"elements": {
			"h1": {
				"typography": {
					"fontSize": "3.625rem",
					"lineHeight": "1.2"
				}
			},
			"h2": {
				"typography": {
					"fontSize": "clamp(2.625rem, calc(2.625rem + ((1vw - 0.48rem) * 8.4135)), 3.25rem)",
					"lineHeight": "1.2"
				}
			},
			"h3": {
				"typography": {
					"fontSize": "var(--wp--preset--font-size--x-large)"
				}
			},
			"h4": {
				"typography": {
					"fontSize": "var(--wp--preset--font-size--large)"
				}
			},
			"h5": {
				"typography": {
					"fontSize": "var(--wp--preset--font-size--medium)",
					"fontWeight": "700",
					"textTransform": "uppercase"
				}
			},
			"h6": {
				"typography": {
					"fontSize": "var(--wp--preset--font-size--medium)",
					"textTransform": "uppercase"
				}
			},
			"heading": {
				"typography": {
					"fontWeight": "400",
					"lineHeight": "1.4"
				}
			}
		}
	}

To target heading blocks but not any other headings:

	"styles": {
		"elements": {
			"core/heading": {
				"color": {
					"background": "red"
				}
			}
		}
	}

@bph bph added has dev note when dev note is done (for upcoming WordPress release) and removed Needs Dev Note Requires a developer note for a major WordPress release cycle labels Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Heading Affects the Headings Block has dev note when dev note is done (for upcoming WordPress release)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants