-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Alignment is handled inconsistently across blocks #4010
Comments
Thanks for the detailed report, @bradyvercher. This seems like it will need to be addressed with several pull requests. |
Some of the bugs in this report have already been fixed, but it still feels like the way alignment is handled was written by several different developers in different ways. I've also noticed third-party blocks have started implementing alignment incorrectly since there isn't really any consistency to the way it's handled in the core blocks. I haven't dug into #4069, but it looked like that would solve a lot of issues and make it easier for plugin developers to support alignment in their blocks. |
This ticket was mentioned in Slack in #core-editor by jeffpaul. View the logs. |
May be addressed by #5099 |
Because this issue was originally filed ~6 months ago and some parts of it were outdated, I have tested each part and moved anything still valid to new issues. Bugs
Needs Decision
Could not reproduce or wontfix:
Tested using WordPress 4.9.7 and Gutenberg 3.2.0. Need help testing:
Closing in favor of newer issues to make some of the issues raised more approachable and this issue (although closed) will remain as a good reference point. Also removed the |
Issue Overview
The implementation of the alignment toolbar is inconsistent between blocks. Aside from not setting a good example for third-party blocks, it exhibits a few bugs, and causes unexpected behavior that's confusing for users.
Attribute Defaults
Some blocks register a default value for the
align
attribute, while others don't. The button, gallery, and pullquote blocks set a default value ofnone
; latest posts usescenter
; and the categories block doesn't set a default, but the PHP render method forces the value tocenter
.For blocks that implement alignment, these are the registered defaults:
null
'none'
null
(defaults to'center'
in the PHP render method)null
null
'none'
null
null
'center'
null
'none'
null
null
null
null
Unaligning Blocks
When unaligning many blocks (deselecting an alignment button), a class of
alignundefined
is applied instead of either removing the alignment class altogether or replacing it with the registered default.Using the button block as an example:
alignnone
)alignleft
)alignundefined
)At this very least, I believe this happens for buttons, galleries, and pullquotes.
Aside from applying an
alignundefined
class, many blocks also throw validation errors when unaligning them.This affects buttons, headings, paragraphs, pullquotes, and quotes.
Edit Wrapper Data Attribute
Most of the blocks apply a
data-align
attribute to the edit wrapper with the alignment value similar to this:Center aligning never seems to change the value of the data attribute for the edit wrapper despite it being a valid value for most blocks. It seems like this should be applied consistently in case themes treat
aligncenter
different thanalignnone
or an empty value.Toolbar onChange Callback
Some blocks define a class method (requires binding in the constructor), others define a local function, and some use an inline arrow function. They all do the same thing. I'd like to see this be more consistent across blocks.
Considering how simple it is, I think using an inline arrow function would make things more concise and easier to read:
Miscellaneous Alignment Issues
Audio Block
Aligning an audio block left or right, then deselecting the block makes it almost invisible in Chrome.
Button Block
Full and wide alignments aren't applied to the edit wrapper in
getEditWrapperProps()
:Categories
The PHP render method forces an
aligncenter
class to be applied even when an alignment button isn't selected in the toolbar.Cover Images
Alignment classes aren't applied in the
save()
method at all.Latest Posts
Unaligning the block doesn't work;
aligncenter
is reapplied when saving. If this is how defaults are handled, then it shouldn't be possible to deselect the alignment button in the UI.Paragraph Block
The attribute name for the block-level alignment is
width
, which doesn't seem to make much sense. Naming this something likeblockAlign
would be a little more clear, especially since thewidth
attribute is a number in some other blocks.Or the inline alignment attribute could be named
textAlign
since that's the property used when applying the inline style.Text Columns
Uses the
width
attribute for alignment.The text was updated successfully, but these errors were encountered: