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

Add option for vertical orientation of Buttons block #20160

Closed
wants to merge 23 commits into from

Conversation

nfmohit
Copy link
Member

@nfmohit nfmohit commented Feb 11, 2020

Description

This PR tries to close #20081 which requests the addition of a vertical style to the buttons block.

How has this been tested?

This PR has been tested by going through the following steps:

  1. Started a new post using the Gutenberg editor.
  2. Added the "Buttons" block.
  3. Changed the block to "Vertical"
  4. Made sure buttons show up in a vertically stacked style.

Screenshots

Types of changes

Non-breaking enhancement

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.

@Soean Soean added the [Block] Buttons Affects the Buttons Block label Feb 11, 2020
@nfmohit nfmohit self-assigned this Feb 11, 2020
@talldan talldan added the [Type] Enhancement A suggestion for improvement. label Feb 12, 2020
@talldan
Copy link
Contributor

talldan commented Feb 12, 2020

Hey @nfmohit-wpmudev, thanks for picking this one up!

One issue I spotted is that when the direction changes to vertical, the block mover buttons are still horizontal:
https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/buttons/edit.js#L33

I think this will be where using a style variation for the horizontal setting is not ideal, as it's difficult to detect when that option is active and then change the mover direction prop.

I'll add the Needs Design Feedback label so we can get some ideas on how this option should be presented.

@talldan talldan added the Needs Design Feedback Needs general design feedback. label Feb 12, 2020
@shaunandrews
Copy link
Contributor

How could we handle alignment of the buttons? For example, if I want the buttons to be left, center, or right aligned?

@talldan
Copy link
Contributor

talldan commented Feb 12, 2020

How could we handle alignment of the buttons? For example, if I want the buttons to be left, center, or right aligned?

@shaunandrews The Buttons block has alignment options. That still seems to work fine in the PR.

@nfmohit
Copy link
Member Author

nfmohit commented Feb 12, 2020

Hey @talldan ! 👋
I hope you are doing well! ❤️

Thank you very much for the review! I'm open to making any changes or adopting any different process for this here. Looking forward to the design review.

Thank you ❤️

@paaljoachim
Copy link
Contributor

This looks really good! A very useful feature!
I agree with Dan @talldan . Switching to a vertical style it would be very helpful to have the block mover in the correct place to reflect the style used.

Thank you Nahid for working on this feature!
@nfmohit-wpmudev

@MichaelArestad
Copy link
Contributor

The behavior of the vertical Buttons style variant is just about perfect. The only issue I noted was the floating of the Buttons block container when aligned left or right. I'm unclear if that behavior would be expected by others. I expected the buttons to be text-aligned left or right instead of having the entire group floated.

Here's a screenshot of the current behavior:
image

Here's a screenshot of what I expected:
image

@MichaelArestad MichaelArestad removed the Needs Design Feedback Needs general design feedback. label Mar 4, 2020
@ZebulanStanphill
Copy link
Member

@MichaelArestad The align-left/align-right actually being floats is a naming issue WordPress has had for years since the alignment tools for images were introduced in the classic editor. There's some discussion about it in #19672.

@MichaelArestad
Copy link
Contributor

@MichaelArestad The align-left/align-right actually being floats is a naming issue WordPress has had for years since the alignment tools for images were introduced in the classic editor. There's some discussion about it in #19672.

Thanks for highlighting that. I was thinking, for this, we could change the controls from "Align" to the text alignment controls seen on a Paragraph block.

@nfmohit nfmohit force-pushed the add/vertical-style-buttons-block branch from 7188561 to e45ebb6 Compare March 16, 2020 15:41
@github-actions
Copy link

github-actions bot commented Mar 16, 2020

Size Change: +3.84 kB (0%)

Total Size: 1.13 MB

Filename Size Change
build/a11y/index.js 1.14 kB +1 B
build/annotations/index.js 3.62 kB +3 B (0%)
build/api-fetch/index.js 3.4 kB +3 B (0%)
build/autop/index.js 2.83 kB +1 B
build/block-directory/index.js 6.77 kB +294 B (4%)
build/block-directory/style-rtl.css 892 B +104 B (11%) ⚠️
build/block-directory/style.css 892 B +104 B (11%) ⚠️
build/block-editor/index.js 106 kB +641 B (0%)
build/block-editor/style-rtl.css 11.8 kB +744 B (6%) 🔍
build/block-editor/style.css 11.8 kB +739 B (6%) 🔍
build/block-library/editor-rtl.css 7.89 kB +689 B (8%) 🔍
build/block-library/editor.css 7.89 kB +690 B (8%) 🔍
build/block-library/index.js 127 kB +8.72 kB (6%) 🔍
build/block-library/style-rtl.css 7.72 kB +246 B (3%)
build/block-library/style.css 7.73 kB +249 B (3%)
build/block-serialization-default-parser/index.js 1.88 kB -1 B
build/blocks/index.js 48.1 kB +7 B (0%)
build/components/index.js 195 kB +4.8 kB (2%)
build/components/style-rtl.css 19.5 kB +2.41 kB (12%) ⚠️
build/components/style.css 19.5 kB +2.42 kB (12%) ⚠️
build/core-data/index.js 11.4 kB +25 B (0%)
build/data-controls/index.js 1.29 kB -1 B
build/data/index.js 8.45 kB +27 B (0%)
build/date/index.js 5.47 kB +3 B (0%)
build/deprecated/index.js 772 B +1 B
build/dom-ready/index.js 569 B +1 B
build/dom/index.js 3.17 kB +54 B (1%)
build/edit-navigation/index.js 8.25 kB +1.62 kB (19%) ⚠️
build/edit-navigation/style-rtl.css 918 B +61 B (6%) 🔍
build/edit-navigation/style.css 919 B +63 B (6%) 🔍
build/edit-post/index.js 303 kB +340 B (0%)
build/edit-post/style-rtl.css 5.6 kB -6.62 kB (118%) 🏆
build/edit-post/style.css 5.6 kB -6.62 kB (118%) 🏆
build/edit-site/index.js 15.5 kB +1.54 kB (9%) 🔍
build/edit-site/style-rtl.css 2.96 kB -2.57 kB (86%) 🏆
build/edit-site/style.css 2.96 kB -2.57 kB (86%) 🏆
build/edit-widgets/index.js 9.34 kB +1.29 kB (13%) ⚠️
build/edit-widgets/style-rtl.css 2.4 kB -2.19 kB (91%) 🏆
build/edit-widgets/style.css 2.4 kB -2.19 kB (90%) 🏆
build/editor/index.js 44.8 kB +199 B (0%)
build/editor/style-rtl.css 4.26 kB -793 B (18%) 👏
build/editor/style.css 4.27 kB -793 B (18%) 👏
build/element/index.js 4.64 kB -2 B (0%)
build/format-library/index.js 7.72 kB +15 B (0%)
build/hooks/index.js 2.13 kB -2 B (0%)
build/html-entities/index.js 621 B -1 B
build/i18n/index.js 3.56 kB +1 B
build/is-shallow-equal/index.js 710 B -1 B
build/keyboard-shortcuts/index.js 2.52 kB +7 B (0%)
build/keycodes/index.js 1.94 kB +1 B
build/list-reusable-blocks/index.js 3.12 kB -1 B
build/media-utils/index.js 5.3 kB +10 B (0%)
build/notices/index.js 1.79 kB +3 B (0%)
build/nux/index.js 3.41 kB +5 B (0%)
build/plugins/index.js 2.56 kB -6 B (0%)
build/primitives/index.js 1.5 kB +1 B
build/redux-routine/index.js 2.85 kB -3 B (0%)
build/rich-text/index.js 14.8 kB +5 B (0%)
build/server-side-render/index.js 2.68 kB +8 B (0%)
build/url/index.js 4.06 kB +41 B (1%)
build/viewport/index.js 1.85 kB +7 B (0%)
build/wordcount/index.js 1.17 kB -2 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/blob/index.js 620 B 0 B
build/block-library/theme-rtl.css 684 B 0 B
build/block-library/theme.css 686 B 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/compose/index.js 9.31 kB 0 B
build/editor/editor-styles-rtl.css 425 B 0 B
build/editor/editor-styles.css 428 B 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/priority-queue/index.js 789 B 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.28 kB 0 B
build/warning/index.js 1.14 kB 0 B

compressed-size-action

@nfmohit
Copy link
Member Author

nfmohit commented Mar 16, 2020

Thank you for your review @MichaelArestad !

One issue I spotted is that when the direction changes to vertical, the block mover buttons are still horizontal:
https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/buttons/edit.js#L33

I think this will be where using a style variation for the horizontal setting is not ideal, as it's difficult to detect when that option is active and then change the mover direction prop.

I completely agree with you there @talldan. I've tried but couldn't find a simple way to get the style as a prop. There are custom hacks, but I'm sure they're not ideal to use. Do you have any recommendations on our way forward here?

@talldan
Copy link
Contributor

talldan commented Mar 19, 2020

@nfmohit-wpmudev I think potentially using a style variation might not be the best way to go for this. Maybe a simple RadioControl (https://github.com/WordPress/gutenberg/tree/master/packages/components/src/radio-control#design-guidelines) that sets an attribute could be an option. That attribute could then be used to set the mover direction and a class name.

It could also be a toolbar option (a bit like Media and Text has for Show Media on Right / Left), but it'd need a good icon. Will add Needs Design Feedback again to see if we can get some feedback on this option.

@talldan talldan added the Needs Design Feedback Needs general design feedback. label Mar 19, 2020
@paaljoachim
Copy link
Contributor

I added a link to the "Navigation Block: add support for vertical menus" above. Both are looking for a good way to add verticality.

@ZebulanStanphill
Copy link
Member

@talldan

It could also be a toolbar option (a bit like Media and Text has for Show Media on Right / Left)

It's worth noting that in that case, the option is an attribute because it actually changes the HTML markup, so that the DOM order continues to match the visual order. In the case of the Buttons block, a vertical style doesn't change the visual order of the buttons.

I'd be wary of adding block attributes for something that can be accomplished through styling alone.

@talldan
Copy link
Contributor

talldan commented Mar 20, 2020

It's worth noting that in that case, the option is an attribute because it actually changes the HTML markup, so that the DOM order continues to match the visual order. In the case of the Buttons block, a vertical style doesn't change the visual order of the buttons.

I'd be wary of adding block attributes for something that can be accomplished through styling alone.

@ZebulanStanphill In this case a value is needed for the InnerBlocks __experimentalMoverDirection prop. This isn't something that should be achieved through styling alone.

@nfmohit
Copy link
Member Author

nfmohit commented Mar 20, 2020

Thank you very much for your inputs everyone. I'm looking forward to the design feedback and then will be happy to move ahead with the suggested solution.

@ZebulanStanphill
Copy link
Member

ZebulanStanphill commented Mar 20, 2020

@ZebulanStanphill In this case a value is needed for the InnerBlocks __experimentalMoverDirection prop. This isn't something that should be achieved through styling alone.

Then I think the way the mover direction is handled needs to be tweaked.

It would make more sense if the mover direction could be changed based on the block style, by specifying the desired orientation when you register a style variation. That way, themes (and eventually also users) could add their own block styles that change horizontal things to vertical, and change the mover orientation as needed.

@nfmohit
Copy link
Member Author

nfmohit commented Mar 20, 2020

Then I think the way the mover direction is handled needs to be tweaked.

It would make more sense if the mover direction could be changed based on the block style, by specifying the desired orientation when you register a style variation. That way, themes (and eventually also users) could add their own block styles that change horizontal things to vertical, and change the mover orientation as needed.

I agree with @ZebulanStanphill here. I feel the best way to visually present a style like this is definitely using block styles. In this case, the change should be considered in either the mover, or ideally in the Block Styles so that some kind of a value can be extracted along with the addition of a CSS class.

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.

LGTM from a code point of view, and worked well when I tested.

Regarding that remaining alignment issue, maybe move that to a separate issue/PR so that it's captured after this one's merged.

I still think it'd be great to get some feedback from a design point of view. Maybe you could drop a note in the #design slack channel @nfmohit-wpmudev?

I'd like to think any of those changes could be worked on iteratively though, and what's currently in this PR is a good first step.

Edit: I renamed the PR so that it's more descriptive in the changelog.

@talldan talldan changed the title [Enhancement] Added a vertical style to the Buttons block Add option for vertical orientation of Buttons block Jun 4, 2020
@paaljoachim
Copy link
Contributor

paaljoachim commented Jun 4, 2020

Taking a look at gutenberg.run.
There are discoverability issues in relation to selecting Button (child) <-> Buttons (parent). A sideline to this issue. It is easier now with the Select parent icon in the toolbar.

Back on track.
Selecting Buttons the Buttons Settings are obvious to notice.
Clicking Vertical the buttons are alined nicely on top of each other.

Hit zone around each individual button in vertical mode is larger compared to the hit zone for horizontal mode. Making it harder to click just outside the buttons to select the parent Buttons block. There seems to be a grey zone buffer area. Clicking into it might select a button or the parent Buttons.

Buttons-hit-zone

Regarding alignment.
It seems like it jumps up and down the page at the same time one clicks the alignment icons.
Buttons-alignment

For instance with alignment (none)
Screen Shot 2020-06-04 at 13 46 54

Then switching to alignment right. Is lower then alignment none.
Screen Shot 2020-06-04 at 13 47 14

An inserter suddenly showed up to the right of the vertical menu. As I was clicking randomly to select the parent Buttons block.
Screen Shot 2020-06-04 at 13 45 43


EDIT:
Conclusion as I see it to the above is that the vertical Buttons row are in the same horizontal line. That the center alignment does not jump further up the page vertically compared to left and right alignment. I think that is about what can be done with that in this PR.

@ZebulanStanphill
Copy link
Member

Again, I don't think the Buttons block should even have the center/left/right "alignment" options. They don't make sense for the block. The block should have item alignment options like the Navigation block.

@paaljoachim
Copy link
Contributor

I will mention this alignment issue. I am not sure if it has relevance to this PR but will add it anyway.
Buttons Block: Centre aligned button isn't centre in the editor
#21805
Another view which I closed as a duplicate issue: #23010

@nfmohit
Copy link
Member Author

nfmohit commented Jun 11, 2020

Thank you for your observations @paaljoachim !

@talldan When you have a minute, could you possibly take a look at the points @paaljoachim mentioned and point me towards a direction? The discoverability issue is something I have noticed myself too. Is that something we should address in this PR?

For the alignment and the spacing issue, I think that also exists for the horizontal orientation and is not only specific for the vertical orientation. Ideas?

I'm not able to replicate the issue with that random inserter.

I'm a bit confused with the way to go forward. I'm also considering @ZebulanStanphill's feedback here and thinking about revamping the alignment options in a new PR.

Once we address the above concerns, I'll surely go ahead and request feedback from the #design channel. I'll be grateful for any suggestion. Thank you guys!

@talldan
Copy link
Contributor

talldan commented Jun 11, 2020

@nfmohit-wpmudev Looks to me like the bug @paaljoachim mentioned is also in master, so it wasn't caused by this PR.

Efforts to fix it separately would be greatly appreciated. @paaljoachim would you be able to make an issue?

I don't think there are any other blockers, other issues could be tackled separately. But I do still think it'd be good to get a design thumbs up on this as a first draft, there wasn't much input from design throughout developing this feature.

Eventually I think this option could become a Block Variation, but there are a few issues that need to be tackled before that:

Possibly also:

@paaljoachim
Copy link
Contributor

paaljoachim commented Jun 11, 2020

Hey @talldan

First off I believe there should be a common approach and UI method for the showing of vertical orientation for the Navigation block, Social Icons block and the Buttons block. Styles for the Buttons block work really well, as a style is something that affects the look of the block. The same method should then also be applied to other related blocks.

Are you thinking of the bug I mentioned where the vertical Buttons Block jumps higher up vertically on the page?

@talldan
Copy link
Contributor

talldan commented Jun 11, 2020

Hey @paaljoachim Yep, I think the common approach would be to use Block Variations, which the navigation block started doing. The navigation block is experimental though, those two issues I mentioned need to be solved before this can really be tried on a non-experimental block.

Are you thinking of the bug I mentioned where the vertical Buttons Block jumps higher up vertically on the page?

Yep, that's what I was referring to. 👍

@paaljoachim
Copy link
Contributor

I wonder if we can temporarily add the vertical style for the Buttons Block.

In the following comment I am suggesting a new panel named Layout to be used for layout variations. #20584 (comment)

Here is a new issue for the jumping up and down of the vertical Buttons Block.
#23087 (Dan please rephrase the issue as you see fit.)

@MichaelArestad
Copy link
Contributor

I think there likely needs to be some followup PRs to this. I'm going to list a few of the bugs I noticed:

  1. Align Center and Align Right only align the container to the right. You can see the buttons are still left-aligned within the container:

image

  1. The Button block focus style is as wide as the widest button rather than the width of the button itself:
    image

  2. Similar to an above bug, when I transform from Horizontal to vertical, the selected Button state is as wide as the editor:
    image

I would like to see these all resolved if possible before I would recommend merging this PR.

As far as design, I'm not sure the sidebar is the right place. Perhaps block variations (like the nav block) would make more sense. For now, I'm okay with it in the sidebar, but I think the section label needs to change from "Button Settings" to "Layout."

@ZebulanStanphill
Copy link
Member

@MichaelArestad It's not a bug for only the container to be aligned by the block alignment options. Rather, it's probably a bug that the Buttons block even has center/left/right block alignment options in the first place. It should have item alignment/justification options instead. Perhaps a new PR should be opened to resolve this issue first?

@nfmohit
Copy link
Member Author

nfmohit commented Jun 12, 2020

Thank you for your feedback @MichaelArestad !

I second what @ZebulanStanphill's said. What do you think @talldan @MichaelArestad ?

@paaljoachim
Copy link
Contributor

A quick mockup comparing the two.

Buttons settings.
Screen Shot 2020-06-12 at 10 15 25

Layout
Buttons-Block-Layout

@MichaelArestad
Copy link
Contributor

It should have item alignment/justification options instead. Perhaps a new PR should be opened to resolve this issue first?

@ZebulanStanphill @nfmohit-wpmudev It took me a minute to understand the distinction, but that makes sense. I'd like to see the current control removed in the meantime as I think it just adds confusion rather than working as expected.

@ZebulanStanphill
Copy link
Member

I began work on #23168 to overhaul the alignment/justification controls. However, I realized that to get the implementation working better, I should first update the block's editor markup to match the front-end more closely.

So I created #23222 to do that, but now that PR is stuck due to technical complications with the unique way the Buttons block disables alignment controls for nested Button blocks.

I have a hunch that the changes in #23034 might help with all this, but that PR is also in need of technical help at the moment.

So unfortunately, I think it's going to take some time before this PR can get merged, if we want to make sure the existing features on the Buttons block are polished and working before adding any more. 😞

@youknowriad
Copy link
Contributor

#23034 is merged, does it unblock this one?

@ZebulanStanphill
Copy link
Member

ZebulanStanphill commented Oct 1, 2020

@youknowriad Technically, #23168 is the PR that is blocking this one. And speaking of which, that PR should be ready for an initial review now, since #23222 was merged.

@shaunandrews
Copy link
Contributor

shaunandrews commented Oct 16, 2020

I'm unable to get this PR running, but I believe (as mentioned above) the horizontal/vertical option should be a Variation of the button block rather than a Style. The Buttons block already contains two Styles; Fill and Outline.

Screen Shot 2020-10-16 at 2 21 00 PM

If we add horizontal and vertical Styles, I think we'd have to actually add more styles to account for the combination of Fill, Outline, Horizontal, and Vertical. (i.e. Horizontal Filled, Horizontal Outline, etc, etc)

@paaljoachim
Copy link
Contributor

paaljoachim commented Oct 18, 2020

I tested Social Icons block to compare how things are done there.
Styles are located in the parent (Social Icons) sidebar options.
There should be an option to have horizontal/vertical options in Social Icons block as well.

Horizontal/vertical options should not be added to the Styles panel. We should create a common phrase/term for these options. Perhaps (as I mentioned above) "Layout" or "Structure". Layout could perhaps also be used for other blocks where one adjusts the layout/structure of a block. We need a new term for structural adjustments.

For horizontal/vertical structure. For Column block structure. For Media & Text structure. Etc.

@talldan
Copy link
Contributor

talldan commented Oct 19, 2020

@shaunandrews Unfortunately the screenshot in the description is outdated, I've removed it!

Currently it's implemented as a radio button like @paaljoachim's comment here - #20160 (comment)

This can be migrated to a block variation in the future, but it hasn't been implemented that way right now as I don't think there's a way to switch between variations easily (which feels like something that will be needed).

@ZebulanStanphill
Copy link
Member

#23168 is merged now, so this can be rebased to work with the new content justification controls.

@paaljoachim
Copy link
Contributor

What is needed to move this PR onward?
It would be nice with a status update to where this PR is at.

Thanks!

@paaljoachim
Copy link
Contributor

I believe this PR could use the same treatment as the vertical/horizontal variation that was added to the Navigation block.
#26687 by @ntsekouras Nik.

@ntsekouras
Copy link
Contributor

I believe this PR could use the same treatment as the vertical/horizontal variation that was added to the Navigation block.

Yeah, I think it's a very similar use case and could work well with the variations. We don't need to expose them to the inserter though. We could just set as default the current layout.

@ntsekouras
Copy link
Contributor

After discussing with @nfmohit in DM, he informed me that he doesn't have much time to finish up here (fortunately for good reasons), so I'm closing this one in favor of this:#27297 that will use block variations.

Thanks for your work @nfmohit !

@ntsekouras ntsekouras closed this Nov 26, 2020
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 Needs Design Feedback Needs general design feedback. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "Vertical" block style to buttons block
9 participants