-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Button Block]: Add padding block support #31774
[Button Block]: Add padding block support #31774
Conversation
cb4fb84
to
e85cfce
Compare
@@ -225,6 +227,7 @@ function ButtonEdit( props ) { | |||
? borderRadius + 'px' | |||
: undefined, | |||
...colorProps.style, | |||
...spacingProps.style, |
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.
Should this be ported to edit.native.js as well? Asking because I don't know :) and I can't yet get the native mobile test env running locally.
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.
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 looking great.
We need to import the new hook getSpacingClassesAndStyles
in index.native.js
Since this PR doesn't add the button padding controls to native there's no change. Should we add it in another PR?
Thanks for the thorough testing @ramonjd -- I think the controls should be added to native in this PR as well. I'll get that added! |
62fd58d
to
51b7ef2
Compare
I took a stab at adding native support for the button padding here: #32218. Until the I updated this PR with the native exports so that it does not cause errors in the app, but think it might be better to continue work on the mobile side in a separate PR. |
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.
Nice!
I retested this PR on desktop and native mobile.
Desktop button padding support works as described in the test steps:
Buttons controls on native work as expected in the editor and frontend after controls extraction:
I updated this PR with the native exports so that it does not cause errors in the app, but think it might be better to continue work on the mobile side in a separate PR.
Good point. 👍 Will be easier to test in a new PR too.
Thanks for working on this. Per the improvements that @aaronrobertshaw has been exploring with regards to a specific "Dimensions" panel, can we leverage some of that work for this one? See also #32499 for an example of that panel. |
The changes in #32392 will be picked up by all blocks using spacing support once it lands. The "Spacing" panel and padding control shown in the gif in the PR description are injected by block supports. #32392 updates the panel injected by the spacing support to use the new progressive disclosure block support panel. |
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.
Nice work @stacimc ✨
This tests well for me.
- Individual button padding gets updated appropriately in the block editor and frontend
- Setting padding for buttons through the Global Styles works
- Theme.json generated styles also get correctly applied to the button both in editor and frontend
It might be worth raising here that there is a discussion around how we can allow blocks to possibly apply styles from block supports to inner elements such as table rows or nav menus.
If a solution to that is found it might allow the skipping of spacing support serialization in this block to be removed. I don't believe it should block this however.
Before merging we'll need to rebase this PR and get some design feedback that we can land this under the provision that the width and spacing panels will ultimately be unified once block support is updated to provide only a dimensions panel.
Being able to control button padding appears pretty important to me and really helps out block pattern designs.
cc/ @jasmussen Any objections to merging this now?
35c1561
to
44da455
Compare
44da455
to
ef6fb3a
Compare
I retested this today and it all looks good in the editor and frontends. Also rechecked on iOS. I can't see why we couldn't merge this one and wait for the Dimensions UI panel changes to be merged. As I understand it the Dimensions panel only updates the UI and doesn't affect this block's attributes, or requires writing deprecations. Following @aaronrobertshaw's advice and pinging @geriux just to make sure the changes to the web button has no negative effects on native buttons. |
Thanks for the ping! I'll check it out 👍 |
I tested this by creating a post on the web editor with a button block and custom padding (following this PR testing instructions) and there are no negative effects while opening/modifying it on the mobile editor 👍 |
I've given this another quick double check as well. LGTM. |
@@ -199,6 +200,7 @@ function ButtonEdit( props ) { | |||
|
|||
const borderProps = useBorderProps( attributes ); | |||
const colorProps = useColorProps( attributes ); | |||
const spacingProps = useSpacingProps( attributes ); |
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.
Can you clarify why this is needed here? Ideally padding support is enabled for blocks by just adding a block support flag without touching the block itself at all.
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 guess this is because of the extra wrapper of the button block? That wrapper is hurting us a lot, ideally we should find ways to remove it without breaking changes. We tried this in the past but reverted. I wonder if we could make it opt-in somehow.
It seems for now we're just accepting the less than ideal button markup.
cc @mtias
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.
Definitely worth considering and exploring. I'm not too sure of what was the case with the extra wrapper.
I've been chatting to @aaronrobertshaw about this, and working out the best way to represent various configurations in the block supports JSON and/or what we need to do to get the existing control hooks to recognize them to display axial padding controls. I think support for axial spacing can be achieved on top of work he's already done in #30607 and by @andrewserong in #32610. I'll take a closer look. 👍 I can't find any desperate pleas for allowing padding controls on individual edges so far. Still it sounds reasonable to able to specify between axial/individal and so on. |
Merged enums in margin and padding since they can be used together according to WordPress/gutenberg#31774
* Fix margin and padding in block.json Merged enums in margin and padding since they can be used together according to WordPress/gutenberg#31774 * Update block.json
Description
Adds padding support to the Button block using the spacing block support.
Issue #31731
Notes:
The block support currently allows arbitrarily large padding values which can cause blocks implementing it to overflow the page. See #31773
How has this been tested?
Manually.
Test Setup
Your theme will need to opt into padding support. You can do this by updating your
theme.json
to enable padding under the spacing control, in either your default settings or the block context for button:Test Instructions
Screenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).