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

Buttons block: overhaul alignment/justification controls #23168

Merged
merged 5 commits into from
Oct 28, 2020

Conversation

ZebulanStanphill
Copy link
Member

@ZebulanStanphill ZebulanStanphill commented Jun 15, 2020

Purpose

Replaces #23133.

This PR does two things:

  • Changes the valid "block alignment" options of the Buttons block from (left, center, right) to (wide, full).
  • Adds content justification controls (similar to that of the Navigation block)

The left and right options (which, as a reminder, are float options) were not really useful at all for the Buttons block, and the center alignment option is something that probably should've been handled by content justification options from the start.

The left/right content justification options actually give the effect that some may have expected the "block alignment" left and right options to do. I suspect that adding the "block alignment" controls to the Buttons block in the first place was a mistake caused by someone thinking that they were content alignment controls, hence the existing text-align: center style being applied to Buttons blocks with the aligncenter class in order to make the center-block-alignment option act like a center-content-alignment option.

The Navigation block does have support for the wide and full "block alignment" options, and I think there are actually use-cases for those options, so this PR adds support for those two to the Buttons block. If desired, I could remove those options, and thus remove the align attribute from the block entirely.

This PR was motivated by this discussion. I initially tried to do all this in multiple PRs, but I realized that doing so would require multiple deprecations if I didn't get certain changes in soon enough. For that reason, I have opted for a single PR to make all the necessary changes at once so that the proper controls are added at the same time that the confusing weird ones are removed.

Deprecation handling

Buttons block with a center-alignment will also be converted to use content alignment, and in this case the end result will look identical.

Existing Buttons blocks with a left/right float alignment will have that float alignment removed and replaced with left or right content justification, since that is what most people thought the options would do anyway. In fact, the editor styles were (confusingly) already applying some content alignment styles, though they weren't noticeable since the alignxxx classes were also applying float behavior.

The existing front-end styles for block alignment are retained for compatibility with already-published posts that have yet to be reopened in the editor.

How has this been tested?

I tested to make sure existing Buttons blocks using the deprecated align options are converted to the new content justification system as described earlier.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • 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.

@ZebulanStanphill ZebulanStanphill added the [Block] Buttons Affects the Buttons Block label Jun 15, 2020
@github-actions
Copy link

github-actions bot commented Jun 15, 2020

Size Change: +718 B (0%)

Total Size: 1.21 MB

Filename Size Change
build/block-library/editor.css 8.94 kB -1 B
build/block-library/index.js 146 kB +609 B (0%)
build/block-library/style-rtl.css 7.82 kB +54 B (0%)
build/block-library/style.css 7.82 kB +56 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.78 kB 0 B
build/api-fetch/index.js 3.45 kB 0 B
build/autop/index.js 2.84 kB 0 B
build/blob/index.js 665 B 0 B
build/block-directory/index.js 8.72 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/index.js 130 kB 0 B
build/block-editor/style-rtl.css 11.1 kB 0 B
build/block-editor/style.css 11.1 kB 0 B
build/block-library/editor-rtl.css 8.94 kB 0 B
build/block-library/theme-rtl.css 837 B 0 B
build/block-library/theme.css 838 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 48.1 kB 0 B
build/components/index.js 172 kB 0 B
build/components/style-rtl.css 15.4 kB 0 B
build/components/style.css 15.3 kB 0 B
build/compose/index.js 9.81 kB 0 B
build/core-data/index.js 12.3 kB 0 B
build/data-controls/index.js 772 B 0 B
build/data/index.js 8.77 kB 0 B
build/date/index.js 31.8 kB 0 B
build/deprecated/index.js 768 B 0 B
build/dom-ready/index.js 571 B 0 B
build/dom/index.js 4.46 kB 0 B
build/edit-navigation/index.js 11.2 kB 0 B
build/edit-navigation/style-rtl.css 881 B 0 B
build/edit-navigation/style.css 885 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.37 kB 0 B
build/edit-post/style.css 6.36 kB 0 B
build/edit-site/index.js 22 kB 0 B
build/edit-site/style-rtl.css 3.84 kB 0 B
build/edit-site/style.css 3.83 kB 0 B
build/edit-widgets/index.js 26.4 kB 0 B
build/edit-widgets/style-rtl.css 3.09 kB 0 B
build/edit-widgets/style.css 3.09 kB 0 B
build/editor/editor-styles-rtl.css 480 B 0 B
build/editor/editor-styles.css 482 B 0 B
build/editor/index.js 43.1 kB 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.85 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/index.js 7.7 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 623 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 712 B 0 B
build/keyboard-shortcuts/index.js 2.52 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.11 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.34 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.42 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.43 kB 0 B
build/priority-queue/index.js 791 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/reusable-blocks/index.js 3.06 kB 0 B
build/rich-text/index.js 13.2 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.69 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.84 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

@ZebulanStanphill ZebulanStanphill force-pushed the update/buttons-block-align-options branch from e861e17 to a1d12c5 Compare June 15, 2020 23:08
@ZebulanStanphill ZebulanStanphill changed the title Buttons block: change valid alignment options Buttons block: overhaul alignment/justification controls Jun 15, 2020
@ZebulanStanphill ZebulanStanphill added the [Type] Enhancement A suggestion for improvement. label Jun 15, 2020
@ZebulanStanphill ZebulanStanphill force-pushed the update/buttons-block-align-options branch 2 times, most recently from 51cec7c to e9cdc50 Compare June 16, 2020 15:27
@ZebulanStanphill
Copy link
Member Author

ZebulanStanphill commented Jun 16, 2020

Remaining things that need to be addressed for this PR to be ready:

  • Making the content justification control work with the accessible toolbar. Right now it causes the Buttons block toolbar to revert to the one-tab-stop-per-button behavior. I need help to figure this out.
  • Updating the React Native edit implementation. I'm not sure what I need to do here. Any help from the Gutenberg mobile team would be greatly appreciated.
  • Feedback on class names chosen. They're different from the Navigation block intentionally; I intend to update the Navigation block to match in a future PR.
  • Feedback on deprecation approach.
  • Feedback on whether or not the Buttons block should have the wide/full width options or not.

@ZebulanStanphill ZebulanStanphill added the Needs Technical Feedback Needs testing from a developer perspective. label Jun 16, 2020
@ZebulanStanphill ZebulanStanphill force-pushed the update/buttons-block-align-options branch 6 times, most recently from fffa5f9 to 5749cc1 Compare June 16, 2020 22:14
@ZebulanStanphill ZebulanStanphill added the [Status] Blocked Used to indicate that a current effort isn't able to move forward label Jun 16, 2020
@ZebulanStanphill ZebulanStanphill force-pushed the update/buttons-block-align-options branch from 5749cc1 to 9637656 Compare June 21, 2020 22:20
@ZebulanStanphill ZebulanStanphill changed the base branch from master to update/buttons-block-even-lighter-editor-dom September 25, 2020 03:33
@ZebulanStanphill ZebulanStanphill force-pushed the update/buttons-block-align-options branch 2 times, most recently from 0318405 to 63d897a Compare September 25, 2020 04:13
Base automatically changed from update/buttons-block-even-lighter-editor-dom to master September 25, 2020 14:44
@ZebulanStanphill ZebulanStanphill force-pushed the update/buttons-block-align-options branch 3 times, most recently from c9e899f to e17916b Compare October 1, 2020 14:21
@ZebulanStanphill ZebulanStanphill removed the [Status] Blocked Used to indicate that a current effort isn't able to move forward label Oct 1, 2020
@Tug
Copy link
Contributor

Tug commented Oct 15, 2020

Thanks for having a look @geriux !

@ZebulanStanphill Do you mind delaying this PR a bit? We need to find some time for someone to help on that task if we want to avoid this (non-fatal) regression on mobile.

@ZebulanStanphill
Copy link
Member Author

@Tug I'm fine with delaying it. I'd prefer to get it in for WP 5.6, but I understand that it would be best to have someone get a mobile implementation ready first.

@geriux
Copy link
Member

geriux commented Oct 15, 2020

Hey, @ZebulanStanphill 👋 just drafted a PR from your branch adding support for mobile.

@ZebulanStanphill ZebulanStanphill force-pushed the update/buttons-block-align-options branch from 67463b4 to 225ff95 Compare October 15, 2020 18:21
@ZebulanStanphill ZebulanStanphill added Needs Dev Note Requires a developer note for a major WordPress release cycle and removed Needs Technical Feedback Needs testing from a developer perspective. labels Oct 17, 2020
@ZebulanStanphill
Copy link
Member Author

Thanks to @geriux's work in #26166 (which has now been merged into this branch), this PR has a native mobile implementation included, so it is finally complete. All it needs now is an approving review before merge.

Notably, once this is merged, #20160 will be unblocked.

Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

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

Approving from a web point of view. This is working really nicely in my testing! Thanks for persevering, @ZebulanStanphill, and for the mobile implementation @geriux.

@ZebulanStanphill ZebulanStanphill force-pushed the update/buttons-block-align-options branch from 9e5a534 to 4fb29cb Compare October 28, 2020 14:04
@ZebulanStanphill
Copy link
Member Author

Rebased after the changes in #26380. Thanks for all your help getting this PR polished and completed, everyone! The end-to-end test failures are unrelated, so I'm going to go ahead and merge now.

@ZebulanStanphill ZebulanStanphill merged commit a03ea51 into master Oct 28, 2020
@ZebulanStanphill ZebulanStanphill deleted the update/buttons-block-align-options branch October 28, 2020 14:55
@github-actions github-actions bot added this to the Gutenberg 9.3 milestone Oct 28, 2020
stacimc pushed a commit to stacimc/gutenberg that referenced this pull request Oct 29, 2020
PR WordPress#23168 overhauls alignment controls on the Buttons container and
allows for full width. For a Button inside a very large container,
in order to be set correctly to 100% it must be able to exceed any
configured max-width.

This commit does not remove the max-width for any button that does
NOT have a custom width percentage selected. This is so that
default buttons continue to be sized as they normally would.
apeatling pushed a commit that referenced this pull request Nov 3, 2020
* Add sidebar width selector for Button block

Initial commit adding a width option for the Button block with
options at 25, 50, 75, 100% widths. By default none are applied
and the button is sized by its content.

* Persist width changes

* Apply styling through class name rather than inline

* Clean up CSS

* Allow toggling a custom width off

A width selection can now be toggled off by clicking the already
selected option.

* Update InspectorControls to use sentence case

Co-authored-by: Miguel Fonseca <[email protected]>

* Remove max width from buttons with custom width set

PR #23168 overhauls alignment controls on the Buttons container and
allows for full width. For a Button inside a very large container,
in order to be set correctly to 100% it must be able to exceed any
configured max-width.

This commit does not remove the max-width for any button that does
NOT have a custom width percentage selected. This is so that
default buttons continue to be sized as they normally would.

* Apply `has-custom-width` class on frontend

Fixes a bug where the inner button was not being set correctly to 100%
width on the frontend, due to the missing classname.`

Co-authored-by: Staci Cooper <[email protected]>
Co-authored-by: Miguel Fonseca <[email protected]>
@noisysocks noisysocks mentioned this pull request Jan 28, 2021
9 tasks
@youknowriad youknowriad removed the Needs Dev Note Requires a developer note for a major WordPress release cycle label Jun 1, 2021
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 [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants