Description
#73032 added some new default CSS to the Accordion Heading block. Previously, it was easy to style via theme.json. The new CSS now make it harder to style and introduce the same problems that have made it tough for theme authors styling Core blocks over the years. The Accordion block was free of this until this commit.
The following is an example of how this change now makes it too hard to style the Accordion Heading toggle where it was previously easy. It specifically looks at an example with padding, but it looks like the other styles introduced should produce the same issue.
To correct this, any styles need to be lower specificity than those produced from theme.json (or the Styles panel in the Site Editor).
CC: @t-hamano
Step-by-step reproduction instructions
Here is some basic padding on the toggle:
{
"styles": {
"blocks": {
"core/accordion-heading": {
"css": "&__toggle { padding: var(--wp--preset--spacing--40) var(--wp--style--block-gap); }"
}
}
}
}
Fortunately, this works. However, the :hover and :focus additions now break this style because of this CSS:
.wp-block-accordion-heading__toggle:focus,
.wp-block-accordion-heading__toggle:hover {
background-color: inherit !important;
border: none;
box-shadow: none;
color: inherit;
padding: var(--wp--preset--spacing--20, 1em) 0;
text-decoration: none;
}
So, you'd think you could just be more specific with the theme.json CSS:
{
"styles": {
"blocks": {
"core/accordion-heading": {
"css": " .wp-block-accordion-heading__toggle, .wp-block-accordion-heading__toggle:hover, .wp-block-accordion-heading__toggle:focus { padding: var(--wp--preset--spacing--40) var(--wp--style--block-gap); }",
}
}
}
}
This produces (formatted for clarity):
:root :where(
.wp-block-accordion-heading .wp-block-accordion-heading__toggle,
.wp-block-accordion-heading .wp-block-accordion-heading__toggle:hover,
.wp-block-accordion-heading .wp-block-accordion-heading__toggle:focus
) {
padding: var(--wp--preset--spacing--40) var(--wp--style--block-gap);
}
But that still doesn't work because the new Accordion Heading toggle CSS still has a higher specificity.
Of course, !important will work, but that creates a host of other problems like making it harder to overrule via block style variations.
Screenshots, screen recording, code snippet
Shown here while hovering one item:
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.
Description
#73032 added some new default CSS to the Accordion Heading block. Previously, it was easy to style via
theme.json. The new CSS now make it harder to style and introduce the same problems that have made it tough for theme authors styling Core blocks over the years. The Accordion block was free of this until this commit.The following is an example of how this change now makes it too hard to style the Accordion Heading toggle where it was previously easy. It specifically looks at an example with padding, but it looks like the other styles introduced should produce the same issue.
To correct this, any styles need to be lower specificity than those produced from
theme.json(or the Styles panel in the Site Editor).CC: @t-hamano
Step-by-step reproduction instructions
Here is some basic padding on the toggle:
{ "styles": { "blocks": { "core/accordion-heading": { "css": "&__toggle { padding: var(--wp--preset--spacing--40) var(--wp--style--block-gap); }" } } } }Fortunately, this works. However, the
:hoverand:focusadditions now break this style because of this CSS:So, you'd think you could just be more specific with the
theme.jsonCSS:{ "styles": { "blocks": { "core/accordion-heading": { "css": " .wp-block-accordion-heading__toggle, .wp-block-accordion-heading__toggle:hover, .wp-block-accordion-heading__toggle:focus { padding: var(--wp--preset--spacing--40) var(--wp--style--block-gap); }", } } } }This produces (formatted for clarity):
But that still doesn't work because the new Accordion Heading toggle CSS still has a higher specificity.
Of course,
!importantwill work, but that creates a host of other problems like making it harder to overrule via block style variations.Screenshots, screen recording, code snippet
Shown here while hovering one item:
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.