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 alignment not working properly #39937

Closed
HILAYTRIVEDI opened this issue Mar 31, 2022 · 16 comments
Closed

Button Block alignment not working properly #39937

HILAYTRIVEDI opened this issue Mar 31, 2022 · 16 comments
Labels
[Block] Buttons Affects the Buttons Block CSS Styling Related to editor and front end styles, CSS-specific issues. [Type] Bug An existing feature does not function as intended

Comments

@HILAYTRIVEDI
Copy link
Contributor

Description

The button block button is not aligning on the right side in the Twenty Twenty Two theme. It is aligning on the left and center but not on the right side.

Expected

  • Button should be aligned in all directions.

Step-by-step reproduction instructions

  1. Activate the Twenty Twenty Two theme.
  2. Add the button block on teh editor side of the Post or Page.
  3. Try to change the alignment.
  4. You will notice that we can make it center and left align but not right align.the on

Screenshots, screen recording, code snippet

https://www.awesomescreenshot.com/video/8161898?key=5213c5c3ccb17c0c2f23a3c97a583dae

Environment info

  • Gutenberg: 12.9
  • WordPress : 5.9.2

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@akasunil
Copy link
Member

The cause of this issue is justify control in gutenberg button block. Alignment stylesheet get override by Justify control styles. There is solution for this, it more like a patch.

Below style sheet will resolve the issue (See below screenshot for reference ) :

.wp-block-buttons>.wp-block-button.alignright{
    width: 100%;
    text-align: right;
}

Screenshot 2022-03-31 at 6 38 23 PM

While testing this issue, i found out that when we change the justify on button block, alignment control get hidden. not sure why. also not sure why alignment control is added with justify.

@ndiego ndiego added [Block] Buttons Affects the Buttons Block CSS Styling Related to editor and front end styles, CSS-specific issues. [Type] Bug An existing feature does not function as intended labels Apr 3, 2022
@pattyok
Copy link

pattyok commented Apr 15, 2022

I am seeing the same issue with left aligned buttons. Since there are no classes applied just inline styles (!@#$$%) There is no way to override with my own css.

I want two stacked buttons, left aligned.

This is the block editor:
image

This is the result:
image

Related: #38998, #38719

@pattyok
Copy link

pattyok commented Apr 15, 2022

As it turns out if you toggle to center and then back to left it works. So the issue is that the default css applied does not match the default setting in the block.

@strarsis
Copy link
Contributor

strarsis commented May 12, 2022

core/buttons alignment doesn't work for me at all in latest WordPress (5.9.3) + Gutenberg Plugin (13.2.0).
No class or data- attribute (in editor/backend) is assigned, no indication an alignment is applied to the buttons block.
I have to manually assign a CSS class to that buttons block (aligncenter) to see an effect in editor/backend and frontend.

@benknight
Copy link

I'm having the same issue. Alignment doesn't work at all, no classes or attributes are appended in the output HTML after toggling these settings.

@carolinan
Copy link
Contributor

I am not able to reproduce this in WordPress 6.0.2 with and without Gutenberg active.

@kubiqsk
Copy link

kubiqsk commented Nov 25, 2022

I have same issue on multiple websites after update to 6+.
In code editor it looks good - it has all needed values like

<!-- wp:buttons {"className":"","layout":{"type":"flex","justifyContent":"center","orientation":"horizontal"}} -->
<div class="wp-block-buttons"><!-- wp:button {"textColor":"white"} -->
<div class="wp-block-button"><a class="wp-block-button__link has-white-color has-text-color wp-element-button" href="#in-kurze">Übersicht</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->

but on frontend it is like

<div class="wp-block-buttons">
<div class="wp-block-button">
<a class="wp-block-button__link has-white-color has-text-color wp-element-button" href="#in-kurze">Übersicht</a>
</div>
</div>

so there are missing classes like is-content-justification-center and is-layout-flex and wp-container-XXX

resaving does not help

@kubiqsk
Copy link

kubiqsk commented Nov 25, 2022

ok, my issue was, that I was using code to remove that Duotone SVG code generated below <body> and it was removing also some other functionalities probably...

currently I use this and everythign works:

remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );
remove_action( 'in_admin_header', 'wp_global_styles_render_svg_filters' );
remove_action( 'wp_body_open', 'gutenberg_global_styles_render_svg_filters' );
remove_action( 'in_admin_header', 'gutenberg_global_styles_render_svg_filters' );
remove_filter( 'render_block', 'wp_render_duotone_support' );

I removed:

remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
remove_action( 'wp_footer', 'wp_enqueue_global_styles', 1 );
remove_filter( 'render_block', 'wp_render_layout_support_flag' );

@carolinan
Copy link
Contributor

Tested again n WordPress 6.2 alpha without Gutenberg active:

When I first add a button, the right align option is available.
If I select it, the button is not right aligned on the front. And the width settings does not work in the editor.

But if I then select the justify option, the right align option is gone from the toolbar.
And I can't get the align option back without deleting and adding the block again.

Screen.Recording.2023-02-07.at.10.35.55.mov

@carolinan
Copy link
Contributor

@jasmussen Is the justification setting on the button block not intended to completely replace the align right/center/left option?

@jasmussen
Copy link
Contributor

Yes I would think so, part of that was discussed in #44614 as well. That is, through justification, button width, and text align, you should be able to accomplish the use cases shown on that issue.

@carolinan
Copy link
Contributor

OK, I will wait until beta 1 and then test again, it is not working right now unless Gutenberg is activate. But we need to make sure the fix is in 6.2.

@carolinan
Copy link
Contributor

I can confirm that in WordPress 6.2 beta 1, the button can use the width setting (25-100%), be aligned left right and center, and have a text align. It works in the editor and front.

For example it is now possible to have a full with parent buttons block, with a 50% wide button block inside, that is justified to the right, with centered text:

Button justified to the right, centered text

Note that the classname is is-content-justification-right and not aligright

<div class="wp-block-buttons is-content-justification-right is-layout-flex wp-container-2">
<div class="wp-block-button has-custom-width wp-block-button__width-50"><a class="wp-block-button__link wp-element-button">default button</a></div>
</div>

The centered text does not have a class, but if I align the text to the right, there is the has-text-align-rightclass.

<div class="wp-block-buttons is-content-justification-right is-layout-flex wp-container-2">
<div class="wp-block-button has-custom-width wp-block-button__width-50"><a class="wp-block-button__link has-text-align-right wp-element-button">default button</a></div>
</div>

@carolinan
Copy link
Contributor

@HILAYTRIVEDI are you able to confirm as well that the bug has been solved?

@HILAYTRIVEDI
Copy link
Contributor Author

Hi @carolinan , Yes I can confirm that it is now fixed.

@carolinan
Copy link
Contributor

Thank you, great, then we can close this issue.

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 CSS Styling Related to editor and front end styles, CSS-specific issues. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

9 participants