Core/Button .is-style-outline overwrites theme.json padding settings for default button padding
Description
So utilizing theme.json I am able to add styles to the core/button as intended
Though when I change the button style to outline it now ignores my colors (obviously) but what I didn't expect is it overwrote my theme.json padding with its own padding.
Here is the part of my theme.json file
"core/button": {
"color": {
"background" : "var(--wp--preset--color--primary)",
"text" : "var(--wp--preset--color--white)"
},
"spacing": {
"padding": {
"top": "5px",
"right": "15px",
"bottom": "5px",
"left": "15px"
},
"border": {
"customRadius": false
}
}
},
This applies everything as expected but if in the wp-admin area you go and switch style to outline it adds the class
.is-style-outline which then applies its own padding and overwrites my padding.
.is-style-outline>.wp-block-button__link, .wp-block-button__link.is-style-outline {
border: 2px solid;
padding: .667em 1.333em;
}
With this in mind, my thought (though with a grain of salt) would be to either remove the padding from .is-style-outline and let it default to the .wp-block-button__link styles precede.
This creates the problem though of the buttons not being equal in size with default stylings. As the border: 2px solid; will increase the overall size by 4px.
I also thought of maybe changing the border to outline.
Overall I'm not sure the best solution here but that it doesn't seem to be the best way of handling it.
A couple of of other thoughts I had was to have the theme.json file a way of targeting .is-style-outline
Ultimately I think this comes back to the hard coding of styles versus the direction we seem to be going with flexibility.
Step-by-step reproduction instructions
Set a padding in theme.json to apply to core/button
Set button to outline style.
Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
Noting this is still an issue in 14.5.0.
I also just encountered this problem
I'd like to see an option to style the outlined button differently in the theme.josn
I'd like to see an option to style the outlined button differently in the theme.josn
Or disable the option altogether.
Also happens if trying to adjust border width:
theme.json
{
"styles": {
"blocks": {
"core/button": {
"border": {
"width": "4px"
}
}
}
}
}
Doesn't work because the following overrides:
.wp-block-button.is-style-outline > .wp-block-button__link, .wp-block-button .wp-block-button__link.is-style-outline {
border: 2px solid;
padding: .667em 1.333em;
}
I don’t think the padding in that .is-style-outline override should be in the core block library css at all!
I ended up having to add this to the theme’s css stylesheets so the .is-style-outline button matches the styles.elements.button.spacing.padding settings in the theme.json file:
body .wp-block-button.is-style-outline > .wp-block-button__link,
body .wp-block-button .wp-block-button__link.is-style-outline {
padding: 1em 3.5em;
}
Also facing this issue.
Another way that I see this could go would be to have dedicated fields in the theme.json file for Block Styles:
"blocks": {
"core/button": {
"spacing": {
"padding": {
"bottom": "0.25rem",
"left": "1.125rem",
"right": "1.125rem",
"top": "0.25rem"
}
},
"styles": {
"outlined": {
"spacing": {
"padding": {
"bottom": "0.25rem",
"left": "1.125rem",
"right": "1.125rem",
"top": "0.25rem"
}
}
}
}
}
}
Yeah I am finding the inability to style the outline look via theme.json to be horribly inconsistent. Outline style should not be hard coded and should be modifiable without having to rely directly on CSS.
Any updates on this? Seems like we should be able to set defaults for styles (like button > outline) in theme.json. I like @mateuswetah solution.
Any updates on this?
@mateuswetah "styles" doesn't seem to comply upon schema? Wonder how it's working then.?
@mateuswetah "styles" doesn't seem to comply upon schema? Wonder how it's working then.?
It is not @amigoow, that was just a proposal of how things could be set but someone still has to do the job of making it possible...
+1 to @mateuswetah's solution. I would love to see this added asap it's frustrating that we can only set padding for the default button style.
Also facing this problem. +1 to @mateuswetah's solution.
Not only should @mateuswetah's solution be how this is done, it should be possible to create arbitrary new Block Styles (as that phrase was traditionally understood) via theme.json.
I believe it is now possible to override core block style variations in theme.json, if I have understood the issue correctly.
Here's an example:
{
"version": 2,
"styles": {
"blocks": {
"core/button": {
"variations": {
"outline": {
"spacing": {
"padding": {
"top": "0.5rem",
"bottom": "0.5rem",
"right": "2rem",
"left": "2rem"
}
}
}
}
}
}
}
}
Resources:
https://fullsiteediting.com/lessons/modifying-block-style-variations-via-theme-json/
https://make.wordpress.org/core/2023/03/07/miscellaneous-editor-changes-in-wordpress-6-2/#edit-block-style-variations-from-theme-json
Amazing @james-s-k!
I have read that dev. note but I was confusing "Style variations" with "Block variations". I'm glad that this option is now available!
Thanks @james-s-k this works (https://github.com/WordPress/gutenberg/issues/34853#issuecomment-1501928613)
However - while not a show stopper - the issue I'm facing is that WP is generating new style for each outlined button individually i.e.
:root :where(.wp-block-button.is-style-outline--53cf2054d700efe826ae6531dad68027 .wp-block-button__link) {
background: transparent none;
border-color: currentColor;
border-width: 2px;
border-style: solid;
color: currentColor;
padding-top: 0;
padding-right: 2rem;
padding-bottom: 0;
padding-left: 2rem;
}
With tonnes of buttons on a page this generates equally massive amount of redundant and duplicated inline code, not mentioning that to override this style in CSS you practically have to use !importants. This is inconsistent with regular button styling too. Not sure if this justifies opening a new issue.
Yes, this is still an issue, even with the proper structure/syntax. I just came across it with button border-width. Setting it does set the style, but WP's default style is still generated and takes precedent over the style set in theme.json.
The way I override was adding !important, but I really dislike that solution/hack. The custom theme.json should take precedence over the default. Is there even a purpose for the default to be generated at all if it has been changed? Seem like just extra bloat.
"styles":{
"blocks": {
"variations": {
"border": {
"width": "1px !important"
}
}
}
}
The default generated styles and the theme.json-generated share identical specificity, but the default (in my specific theme) are output on line 670, three lines after the theme.json (line 657). I'm sure I don't understand the full reasons why things are output how they are, but it sure seems like customizations in theme.json should be output after defaults in the cascade.