Accordion Heading: Route theme.json spacing to the toggle button - #81976
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @sanketio! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
| * | ||
| * @ticket 79662 | ||
| */ | ||
| public function test_get_stylesheet_targets_accordion_heading_toggle_for_spacing() { |
There was a problem hiding this comment.
I'm not sure if it's worth adding unit tests just for this block. There are many blocks that use __experimentalSelector, and personally, I don't think unit tests are necessary.
There was a problem hiding this comment.
Agreed — removed in 4cfdc70. The two tests above it already cover both selector paths, and this one only asserted one block's block.json.
What?
Closes #79662
Moves the Accordion Heading spacing selector from the legacy
supports.spacing.__experimentalSelectorinto the block'sselectorsmap, sotheme.jsonpadding reaches the toggle button.Why?
The block declares a
selectorsmap holding typography entries only:wp_get_block_css_selector()andgetBlockSelector()consult__experimentalSelectoronly when a block declares noselectorsmap at all, so the spacing selector was never read.theme.jsonpadding was emitted against the wrapper:while the block's own default sits on the toggle:
Two different elements, so a theme can add padding around the toggle but never lower the toggle's own. Asking for
0.25remgrew the heading box from 45px to 53px. Thecssescape hatch was the only way out, which is what #79662 reports.Padding set per block is unaffected either way —
save.jswrites it inline on the button throughgetSpacingClassesAndStyles(), because spacing also sets__experimentalSkipSerialization.How?
One line: adds
"spacing": ".wp-block-accordion-heading .wp-block-accordion-heading__toggle"toselectors, which is the valuewp_get_block_css_selector()would have produced by scoping the legacy selector under the block root.supports.spacing.__experimentalSelectoris left in place. It is unreachable now, but removing it is a separate cleanup and this way the change is purely additive.Colour, border and shadow keep resolving to the block root, matching where
save.jsserializes them.Follow-up to #73454 and #72776, which fixed the specificity of these defaults but not which element the theme's value lands on.
Backward compatibility
Saved markup is untouched —
save()does not read the selector, and the current plus v1/v2/v3core__accordion-headingfixtures all still parse, validate and serialize unchanged.Padding set on an individual block still wins, and so does the
cssescape hatch that #79662 gives as the workaround, so themes already working around this are unaffected. No bundled theme setscore/accordion-headingspacing. Colour, border and shadow are unaffected — the block has noselectors.rootand no root-level__experimentalSelector, so the root selector resolves exactly as before. The support is padding-only, so nothing else moves.The intended change: a theme or a user's Global Styles that sets padding for this block now applies it to the toggle rather than stacking it outside one that never shrank, so a value tuned against the old behaviour will render differently. That is the bug.
:hoverand@mobilepadding follow the same selector now, matching the base styles.Testing Instructions
theme.json, setstyles.blocks.core/accordion-heading.spacing.paddingto something smaller than--wp--preset--spacing--20, e.g.0.25rem.accordion.spec.jspasses (4 tests)Screenshots or screencast
0.25remlands on theh3; toggle keeps 10px; heading box 53pxtheme.json; toggle takes 4px; heading box 33pxUse of AI Tools
Authored with Claude Code under direction and review.