Skip to content
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

Merged

Conversation

stacimc
Copy link
Contributor

@stacimc stacimc commented May 12, 2021

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:

"settings": {
    "spacing": {
        "customPadding": true,
        "units": [
            "px",
            "em",
            "rem",
            "vh",
            "vw"
        ]
    }
}

Test Instructions

  1. Create a post, add a buttons block with a button.
  2. Select the button block and confirm padding controls in the sidebar work, adjusting units/padding per side.
  3. Add another button and confirm that its padding is default. Update its padding and verify that it does not affect the padding of the first button.
  4. Save the post and confirm the padding is visually correct on the frontend.

Screenshots

Screen Capture on 2021-05-27 at 13-55-29

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@stacimc stacimc marked this pull request as ready for review May 12, 2021 23:40
@skorasaurus skorasaurus added the [Block] Buttons Affects the Buttons Block label May 13, 2021
@ramonjd
Copy link
Member

ramonjd commented May 17, 2021

This is testing really well. ✅

button-padding

Editor Frontend
Screen Shot 2021-05-17 at 11 28 37 am Screen Shot 2021-05-17 at 11 28 40 am

I think this PR requires a rebase to fix the failing PHP lint issues.

@stacimc stacimc force-pushed the add/padding-support-button-block branch 2 times, most recently from cb4fb84 to e85cfce Compare May 19, 2021 23:30
@@ -225,6 +227,7 @@ function ButtonEdit( props ) {
? borderRadius + 'px'
: undefined,
...colorProps.style,
...spacingProps.style,
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I got it running and saw that we do have button props. Color and spacing aren't there. Maybe for a follow up PR?

Screen Shot 2021-05-20 at 1 54 04 pm

Copy link
Member

@ramonjd ramonjd left a 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?

@stacimc
Copy link
Contributor Author

stacimc commented May 20, 2021

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!

@stacimc stacimc changed the title Button Block: Add padding block support [WIP] Button Block: Add padding block support May 20, 2021
@stacimc stacimc changed the title [WIP] Button Block: Add padding block support Button Block: Add padding block support May 20, 2021
@stacimc stacimc force-pushed the add/padding-support-button-block branch from 62fd58d to 51b7ef2 Compare May 27, 2021 20:48
@stacimc stacimc changed the title Button Block: Add padding block support [Button Block]: Add padding block support May 27, 2021
@stacimc
Copy link
Contributor Author

stacimc commented May 27, 2021

I took a stab at adding native support for the button padding here: #32218. Until the BoxControl is supported natively, it won't be possible to match the UI exactly without essentially re-implementing that component. There's more information on that PR.

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.

Copy link
Member

@ramonjd ramonjd left a 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:
Screen Shot 2021-05-28 at 2 36 12 pm

Buttons controls on native work as expected in the editor and frontend after controls extraction:

Screen Shot 2021-05-28 at 2 41 49 pm

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.

@jasmussen
Copy link
Contributor

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.

@aaronrobertshaw
Copy link
Contributor

can we leverage some of that work for this one?

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.

Copy link
Contributor

@aaronrobertshaw aaronrobertshaw left a 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?

@stacimc stacimc force-pushed the add/padding-support-button-block branch from 35c1561 to 44da455 Compare July 13, 2021 17:52
@stacimc stacimc force-pushed the add/padding-support-button-block branch from 44da455 to ef6fb3a Compare July 13, 2021 19:03
@ramonjd
Copy link
Member

ramonjd commented Jul 28, 2021

I retested this today and it all looks good in the editor and frontends. Also rechecked on iOS.

button-padding

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.

@geriux
Copy link
Member

geriux commented Jul 28, 2021

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 👍

@geriux
Copy link
Member

geriux commented Jul 28, 2021

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 👍

@aaronrobertshaw
Copy link
Contributor

I've given this another quick double check as well. LGTM.

@aaronrobertshaw aaronrobertshaw merged commit 4c59c1b into WordPress:trunk Jul 29, 2021
@github-actions github-actions bot added this to the Gutenberg 11.3 milestone Jul 29, 2021
@@ -199,6 +200,7 @@ function ButtonEdit( props ) {

const borderProps = useBorderProps( attributes );
const colorProps = useColorProps( attributes );
const spacingProps = useSpacingProps( attributes );
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Member

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.

@mtias
Copy link
Member

mtias commented Jul 30, 2021

@stacimc @ramonjd can we try disabling the granular padding for each edge and only keep general padding and/or axial padding and see if there are any concrete requests for the other?

@ramonjd
Copy link
Member

ramonjd commented Aug 2, 2021

can we try disabling the granular padding for each edge and only keep general padding and/or axial padding and see if there are any concrete requests for the other?

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.

ajlende added a commit to ajlende/schemastore that referenced this pull request Oct 25, 2021
Merged enums in margin and padding since they can be used together according to WordPress/gutenberg#31774
madskristensen pushed a commit to SchemaStore/schemastore that referenced this pull request Oct 25, 2021
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Buttons Affects the Buttons Block
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants