-
Notifications
You must be signed in to change notification settings - Fork 815
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
Add/button block border support #41147
base: trunk
Are you sure you want to change the base?
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
I can't get the Jetpack Beta tester plugin to recognise this branch, so I'm going to switch the PR to ready to review to see if it makes a difference. |
@@ -211,6 +217,36 @@ function get_button_styles( $attributes ) { | |||
$styles[] = 'max-width: 100%'; | |||
} | |||
|
|||
if ( $has_named_border_color ) { | |||
$border_styles['color'] = "var:preset|color|{$attributes['borderColor']}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be working, although looking at the style engine output, $attributes['borderColor']
only contains the last bit of the preset string.
Looking at what's happening over in core, that particular style doesn't seem to be output by the border support either; for preset colors the front end styling depends on the preset classname and its corresponding CSS rule.
I think we'll have to ensure the classname is output on the front end instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I've fixed it to output classname instead of styles.
I've iterated on the feedback and tested the editor changes in wp.com, both on simple and atomic. A design question about these changes: should I attempt to scrap the existing border radius control in the settings tab in favour of the native block support one? I'm not sure what back compat issues that might create. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is generally working as described for me.
✅ controls appear in the editor
✅ style look good in editor and frontend
✅ i can overwrite the button styles in global styles
I see a jetpack button block peculiarity that overrides all border styles for buttons without the is-style-outline
classname.

I was wondering why my styles wouldn't work!
1b98857
to
099816c
Compare
Code Coverage SummaryCoverage changed in 3 files.
Full summary · PHP report · JS report If appropriate, add one of these labels to override the failing coverage check:
Covered by non-unit tests
|
Co-authored-by: Ramon <[email protected]>
Yeah might need to reduce specificity on that rule. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've given this a further test after the recent conflicts were resolved.
All that's left I think is a minor tweak to the default Jetpack forms styles so they don't override the button support border-style
defaults.
Editor | Frontend |
---|---|
![]() |
![]() |
Maybe something like:
diff --git a/projects/plugins/jetpack/extensions/blocks/button/view.scss b/projects/plugins/jetpack/extensions/blocks/button/view.scss
index e3bce484b9..2b5673303d 100644
--- a/projects/plugins/jetpack/extensions/blocks/button/view.scss
+++ b/projects/plugins/jetpack/extensions/blocks/button/view.scss
@@ -17,7 +17,7 @@
color: currentColor;
}
- &:not(.is-style-outline) button {
+ :where(&:not(.is-style-outline) button) {
border: none;
}
}
\ No newline at end of file
To me, it makes sense to consolidate the border styles into a single location under the styles tab. Any backward compatibility issues should be able to be handled via block deprecations here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I missed in my earlier testing was Global Styles, sorry. It looks like we'll need a custom selector added to the block's selectors to apply the border to the inner element.

Also, the naming of the block makes the Global Styles > Blocks results a bit confusing, but that isn't something related to this PR in particular.

Added! Though it's not working for me on the front end 🤔 |
The server-side block registration will need updating as well. However, quickly testing that it still isn't working. I'll have a little more of a dig to see if I can confirm an upstream bug 🕵️ |
🤦 After an embarrassing amount of time following the code, I realised that the global styles were being cached on the front end, and the server-side block registration tweak did in fact work. I've pushed that change as it's working for me. Screen.Recording.2025-03-04.at.5.12.35.pm.mp4 |
Pushed another tweak to fix border reset style when the button block is rendered as a The earlier tweak in d471962 still had a specificity of This is getting pretty close 🤞 ✅ Flat borders work ❓ The only remaining issue I ran into was some default styles overriding global styles when the I think the Jetpack button block might have more issues regarding supporting block style variations through global styles. Perhaps that could be done as a followup? In case it's of use, here's a diff lowering specificity of defaults to allow global styles borders to apply regardless of outline block style. CSS Diff (Note: we need a better solution than this)diff --git a/projects/plugins/jetpack/extensions/blocks/button/editor.scss b/projects/plugins/jetpack/extensions/blocks/button/editor.scss
index 124d209d52..034a127fa3 100644
--- a/projects/plugins/jetpack/extensions/blocks/button/editor.scss
+++ b/projects/plugins/jetpack/extensions/blocks/button/editor.scss
@@ -9,11 +9,14 @@
&.is-style-outline > .wp-block-button__link {
background-color: transparent;
- border: solid 1px currentColor;
color: currentColor;
}
}
+:root :where(.wp-block-jetpack-button.is-style-outline .wp-block-button__link ) {
+ border: solid 1px currentColor;
+}
+
// Support align feature for older themes
.wp-block[data-align]:has(> .wp-block-jetpack-button) {
margin-left: 0;
diff --git a/projects/plugins/jetpack/extensions/blocks/button/view.scss b/projects/plugins/jetpack/extensions/blocks/button/view.scss
index 09cd0b8d4b..9dd4b582f2 100644
--- a/projects/plugins/jetpack/extensions/blocks/button/view.scss
+++ b/projects/plugins/jetpack/extensions/blocks/button/view.scss
@@ -13,10 +13,13 @@
&.is-style-outline > .wp-block-button__link {
background-color: transparent;
- border: solid 1px currentColor;
color: currentColor;
}
+ :where(&.is-style-outline > .wp-block-button__link) {
+ border: solid 1px currentColor;
+ }
+
:where(&:not(.is-style-outline) button) {
border: none;
}
Also, these default outline styles are just broken for some buttons in TT5 (and probably more themes). Screen.Recording.2025-03-04.at.5.46.58.pm.mp4Steps to replicate:
|
Thanks @aaronrobertshaw !
I wouldn't worry too much about that, it should be fine to add them as a follow-up. Would those issues be specific to border support or would they affect other styling options? |
Without diving into the code, I suspect they'll prevent any global styles for block style variations to apply. Then there's the fact that the default styles for the outline block style can result in invisible buttons e.g. on TT5. A dedicated follow-up to fix or improve the button block's default styles would make a lot of sense as all these styles are pretty interconnected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're happy to address block style variations (and default styling) in a follow-up, I think this PR is good to go.
In that spirit, I'm happy to give this an approval ✅. Feel free to get a second opinion if you feel it is warranted.
Yes, I think that makes sense. |
Fixes #40696
Proposed changes:
WIP - perhaps should add shadow support too? It's not explicit in the original issue.
Not sure if tests are applicable for this change. Guidance appreciated! It's my first PR to this repo 😊
I tested these changes locally by building the Jetpack env as per these instructions.
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions: