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

Refactor block alignments and margins #20689

Conversation

youknowriad
Copy link
Contributor

No description provided.

@github-actions
Copy link

github-actions bot commented Mar 6, 2020

Size Change: -307 B (0%)

Total Size: 864 kB

Filename Size Change
build/block-editor/index.js 105 kB +87 B (0%)
build/block-editor/style-rtl.css 10.5 kB +42 B (0%)
build/block-editor/style.css 10.5 kB +42 B (0%)
build/block-library/editor-rtl.css 7.28 kB -81 B (1%)
build/block-library/editor.css 7.28 kB -80 B (1%)
build/block-library/index.js 116 kB -10 B (0%)
build/block-library/style-rtl.css 7.5 kB +2 B (0%)
build/block-library/style.css 7.51 kB +2 B (0%)
build/components/index.js 191 kB +3 B (0%)
build/edit-post/style-rtl.css 8.48 kB -158 B (1%)
build/edit-post/style.css 8.48 kB -160 B (1%)
build/editor/index.js 43.9 kB +1 B
build/primitives/index.js 1.49 kB +2 B (0%)
build/rich-text/index.js 14.3 kB +1 B
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.01 kB 0 B
build/annotations/index.js 3.43 kB 0 B
build/api-fetch/index.js 3.39 kB 0 B
build/autop/index.js 2.58 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 6.02 kB 0 B
build/block-directory/style-rtl.css 760 B 0 B
build/block-directory/style.css 760 B 0 B
build/block-library/theme-rtl.css 669 B 0 B
build/block-library/theme.css 671 B 0 B
build/block-serialization-default-parser/index.js 1.65 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 57.6 kB 0 B
build/components/style-rtl.css 15.6 kB 0 B
build/components/style.css 15.5 kB 0 B
build/compose/index.js 5.76 kB 0 B
build/core-data/index.js 10.6 kB 0 B
build/data-controls/index.js 1.03 kB 0 B
build/data/index.js 8.22 kB 0 B
build/date/index.js 5.37 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.06 kB 0 B
build/edit-post/index.js 90.9 kB 0 B
build/edit-site/index.js 4.64 kB 0 B
build/edit-site/style-rtl.css 2.51 kB 0 B
build/edit-site/style.css 2.51 kB 0 B
build/edit-widgets/index.js 4.42 kB 0 B
build/edit-widgets/style-rtl.css 2.59 kB 0 B
build/edit-widgets/style.css 2.58 kB 0 B
build/editor/editor-styles-rtl.css 325 B 0 B
build/editor/editor-styles.css 327 B 0 B
build/editor/style-rtl.css 3.98 kB 0 B
build/editor/style.css 3.98 kB 0 B
build/element/index.js 4.45 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.6 kB 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/hooks/index.js 1.92 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.48 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.3 kB 0 B
build/keycodes/index.js 1.68 kB 0 B
build/list-reusable-blocks/index.js 2.99 kB 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/media-utils/index.js 4.85 kB 0 B
build/notices/index.js 1.57 kB 0 B
build/nux/index.js 3.02 kB 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/plugins/index.js 2.54 kB 0 B
build/priority-queue/index.js 780 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/server-side-render/index.js 2.54 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4 kB 0 B
build/viewport/index.js 1.61 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.18 kB 0 B

compressed-size-action

@@ -56,3 +56,65 @@
@import "./components/editor-skeleton/style.scss";
@import "./components/inserter/style.scss";


// Default styles for alignments in case the theme doesn't provide them.
.wp-block {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally, this should be something that a theme author can copy/paste to its stylesheet and tweak the numbers.
There are some tweaks necessary to achieve it though.

  • We should replace the data-align with the classNames.
  • We should see whether we can remove the wp-block className in favor of something closer to what themes do. Something more like .entry-content > *

When we'll be able to remove IE11 support, we could use CSS variables for the widths and margins.

Copy link
Member

Choose a reason for hiding this comment

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

  • We should see whether we can remove the wp-block className in favor of something closer to what themes do. Something more like .entry-content > *

If we're refactoring now anyway, I really think this is something that we should do now. I see the alignment wrapper as context to a block or blocks, not as a block itself.

Copy link
Member

Choose a reason for hiding this comment

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

Also, if this is the main reason for magically adding the alignment wrapper, and we're going to remove the wp-block class anyway, does it still make sense to magically add it? Tbh, I'd much rather have an explicit component for it instead of magically adding wrappers

Copy link
Member

Choose a reason for hiding this comment

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

My original ideal in #20650 (comment) was to have something like:

<AlignmentWrapper align={align}>
  <Block.figure />
</AlignmentWrapper>

Both in the edit and save function.

return (
<div
className={ classnames( 'wp-block wp-align-wrapper', {
[ `wp-align-${ attributes.align }` ]: !! attributes.align,
Copy link
Member

Choose a reason for hiding this comment

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

Restating my concerns in #20650 (comment), I think now is the prime time to revise the naming scheme for the alignment/position/width options. wp-align-wide shouldn't be a thing because "wide" is not really an alignment, and wp-align-left is misleading if it actually refers to a float.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you propose? for me we should stay consistent in terms of classNames, in terms of labels in the UI it can be different

Copy link
Member

Choose a reason for hiding this comment

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

If we were to put them all under a single naming scheme, I'd go with something like this:

wp-position-xxx with the xxx replaced with one of the following for each of the possible values:

  • align-left (as in actual left alignment)
  • align-right
  • align-center
  • float-left (or maybe pull-left)
  • float-right (or maybe pull-right)
  • stretch-wide-width (or maybe just wide)
  • stretch-full-width (or maybe just full-width)

I'm not sure whether wp-position- is the right naming scheme, though. CSS already has a thing called position that isn't really the same concept. Perhaps it may also be worth distinguishing from potential vertical options by using wp-horizontal-position- or wp-x-position- or something like that.

But I'm not convinced that different options should use the same naming scheme if they're technically different things. If we were to use more diverse names depending on what exactly the position/alignment/whatever actually is, I would go with something like the following:

  • wp-align-left
  • wp-align-right
  • wp-align-center (or possibly wp-align-center-horizontally or wp-align-center-x to distinguish from potential vertical centering or something like that in the future)
  • wp-float-left (or maybe wp-pull-left)
  • wp-float-right (or maybe wp-pull-right)
  • wp-width-wide
  • wp-width-full

I prefer this naming scheme since it's more concise, and doesn't try to fit a redundant, possibly incorrect word like "position" into the class names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we can change the name of the alignments today left/right/wide/full/center are here to stay. I don't think it's worth the hassle to rename these for BC. We should try to figure out a prefix that work well for these. Otherwise, we'll just add complexity to map the alignment name with the classname without high benefits.

Also cc @aduth as my go to naming person :P

Copy link
Member

Choose a reason for hiding this comment

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

@youknowriad wp-align-xxx is already different from the existing alignxxx class names, though, so we're already updating the class names, aren't we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but I'm talking about the attribute values, not the classNames.We also need to keep. BC for existing themes with data-align[value] stylesheets. Again renaming this is possible but not without needless complexity.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we omit the wp- prefix for alignments?

Copy link
Member

Choose a reason for hiding this comment

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

@jasmussen I'm fine with removing them.

Copy link
Member

Choose a reason for hiding this comment

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

@youknowriad Personally, I think that changing the attribute values, even if it means some somewhat complex back-compat, is well worth it to get class names that actually make sense. Changing how block alignments work is likely to break styles anyway, so we might as well take advantage of the opportunity so people don't have to update their styles twice.

Also, do we even need data-align anymore? See #20689 (comment).

} = useContext( BlockContext );
const supportAlignments = hasBlockSupport( name, 'align', false );
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 accept an array of possible alignments?

@@ -199,7 +202,9 @@ const BlockComponent = forwardRef(
{ ...props }
id={ blockElementId }
ref={ wrapper }
className={ classnames( className, props.className ) }
className={ classnames( className, props.className, {
'wp-block': ! supportAlignments,
Copy link
Member

Choose a reason for hiding this comment

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

Why does this class have to be removed when there's alignment? Does it hurt to have .wp-block > .wp-block?

// between blocks in the editor.
.editor-styles-wrapper .block-editor-block-list__block {
margin-top: $default-block-margin;
margin-bottom: $default-block-margin;
Copy link
Member

Choose a reason for hiding this comment

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

I've been wanting to remove this for ages, but there's always been some reason for keeping it. Can it safely be removed now? Cc @jasmussen

Copy link
Contributor

Choose a reason for hiding this comment

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

It seeems like we can! From quick testing in a theme that doesn't style the editor, things look right. And it'd definitely a rule we want to remove. So it does seem now's the time!

Note that these two rules seem to mostly take its place:

Screenshot 2020-03-09 at 13 55 09

and

Screenshot 2020-03-09 at 13 57 06

Good to be mindful of these removals, when we get to the DOM "lightening", can check on a per-block basis, because now it will be up to each individual block to ensure a margin.

@ellatrix
Copy link
Member

ellatrix commented Mar 9, 2020

Theres' now two alignment buttons on thee image block.

@ellatrix
Copy link
Member

ellatrix commented Mar 9, 2020

Screenshot 2020-03-09 at 13 30 47

I cannot click the image block if it's not aligned. For some reason the height is 0.

className={ classnames( 'wp-block wp-align-wrapper', {
[ `wp-align-${ attributes.align }` ]: !! attributes.align,
} ) }
data-align={ attributes.align }
Copy link
Member

Choose a reason for hiding this comment

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

Why are we adding the data attributes here if we're going with classes? I think this will only make things more confusing as it's the old way of styling alignment in the editor.

@jasmussen
Copy link
Contributor

Screenshot 2020-03-09 at 13 57 16

I'm seeing the list block not centered. This is in a theme with no editor style.

@paaljoachim
Copy link
Contributor

paaljoachim commented Mar 9, 2020

I do think I have earlier read it above here.... not able to locate it right now.
There should be a default alignment so that one of the alignment options start off as selected. The user will click the alignment option and already see left alignment default selected and can change it to any of the other alignment options. It right away gives a clarity to the user that default alignment is to the left.

If Global option alignment center is selected the user will see that the default alignment is center.

@ZebulanStanphill
Copy link
Member

@paaljoachim The problem with that is that the default alignment can change based on theme. You need to be able to distinguish between having an alignment set versus just using the default value.

One notable issue with the current "block alignments" UI is that there is no way to explicitly select left alignment (as in actual left alignment, not float left). There's also no way to select actual right alignment for a block, explicit or implicit.

The problem is made worse by the fact that the float options are called alignments, which tend to cause confusion when the user selects them and gets unexpected float behavior.

@jasmussen
Copy link
Contributor

It right away gives a clarity to the user that default alignment is to the left

I'll push back on this one a little bit, because this is only true in the western world via the left to right reading direction.

Additionally, no alignment is also not the same as left alignment. Left aligned is explicitly set: text-align: left; as an inline style, whereas no alignment outputs nothing. You might have a WordPress theme that justifies text, and in that case it's useful to be about to text align left on a per block basis.

@jasmussen
Copy link
Contributor

Snap! Zeb beat me 😅

(And added additional valuable context!)

@ZebulanStanphill
Copy link
Member

To clarify a bit of my previous post, you can explicitly set left/right text alignment in the text alignment toolbar, but no equivalent exists in the "block alignment" toolbar (which contains not just alignments, but also floats and width options, and which probably needs a better name).

@paaljoachim
Copy link
Contributor

paaljoachim commented Mar 9, 2020

I got a feeling that with your replies Zeb and Joen that there is needed some clarity here.

  • Clear naming of the various alignment options.
  • Block alignment options.
  • Text alignment options.
  • Default alignment. Is also an alignment. It could be make clear to the user.

Taking a step back.... I need to take the basic steps.

Using the theme Twenty Twenty as an example.

Text alignment.
Screen Shot 2020-03-09 at 16 46 23

Default text alignment is to the left. Even though it does not by default show.
Left alignment should by default show selected text alignment like so:
Screen Shot 2020-03-09 at 16 49 31
Yes some themes will have the default text alignment to the right or center.

Default image alignment.
Screen Shot 2020-03-09 at 16 46 49

Default image alignment is left but not float. Clicking Align left gives it a float.
Like so.
Screen Shot 2020-03-09 at 16 56 10

Default image alignment is not having any active alignment option selected. As one has to deactivate the image alignment options to get the image to not float and not to center.

My conclusion (see a professor standing infront of the class lecturing) is that we also need alignment options for float of all media.

Does this mean ---> An added icon for float alignment? Or have a multi choice in the same alignment drop down. Select media alignment. Then further below select if you want it to float left,center, right or no float.

@ZebulanStanphill
Copy link
Member

It's not really accurate to highlight an option as if it were selected when in fact it is not. If you explicitly set a block to use an option, that setting will persist across themes and wherever you copy-paste the block to. When an option isn't set (or in some cases set to an "auto"/"default" value), the block's style will depend on what theme and what template and sometimes even what its parent block is.

This does make me wonder if perhaps the alignment toolbars should be refactored into radio option groups, with a clearly visible "auto"/"default" option listed. In fact, that may also increase accessibility. However, that's out-of-scope for this PR.

To be completely clear, in case anyone is confused, the block alignment toolbar is not really just a block alignment toolbar. I would not consider floats to be alignments (or at least, they're a sort of alignment combined with an altered flow in the page), and the wide/full options are definitely not alignments in the traditional sense of the term. The only option that is an actual alignment is the "Align center" option, which actually does simply center the block. The toolbar should probably be called something else, though I'm not sure what name would make the most sense. Block position toolbar, perhaps?

Currently, the "Align left" and "Align right" icons depict float behavior, so those icons should remain the icons for the float icons. New icons should be used for actual left/right alignment options. (Effectively the only difference being the lack of the two short horizontal lines representing text flowing on the side of the block; in other words, the "Align center" icon, but with the middle rectangle pushed to the left or right.)

To summarize, here's my mapping of old to new:

  • "Align left" becomes "Float left"; alignleft becomes float-left
  • "Align right" becomes "Float right"; alignright becomes float-right
  • "Align center" keeps the same visual label; aligncenter becomes align-center
  • "Align wide" becomes "Wide" or "Stretch to wide width" or something like that; alignwide becomes wide-width or width-full or stretch-wide or something similar.
  • "Align full" becomes "Full width" or "Stretch to full width" or something similar; alignfull becomes full-width or width-full or stretch-full-width or something similar.

Additionally, new options for actual left alignment and actual right alignment would be added: "Align left" (align-left) and "Align right" (align-right).

All of this is referring to what is currently called the "block alignment" toolbar. The text alignment toolbar is unaffected by these changes.

@ZebulanStanphill
Copy link
Member

One thing I forgot to mention is that the current icons being used for alignleft and alignright with the latest G2 UI are more suited for actual alignments, yet they're confusingly being used for float controls.
image

@paaljoachim
Copy link
Contributor

Btw here are even more alignment options:
#16738

@ZebulanStanphill
Copy link
Member

Btw here are even more alignment options:
#16738

It's worth noting that in one of the iterations of that PR, the "full screen" option was replaced with a "stretch to viewport height" option that can be toggled separately from the horizontal position/alignment options. You could theoretically introduce other options such as a "stretch to tall" option that makes something about 80% of the viewport height, thus creating a vertical position toolbar, complementing the existing horizontal position/alignment toolbar.
image

@ZebulanStanphill ZebulanStanphill mentioned this pull request Mar 11, 2020
9 tasks
@@ -46,8 +46,8 @@ $z-layers: (
".components-drop-zone": 40,
".components-drop-zone__content": 50,

// The block mover for floats should overlap the controls of adjacent blocks.
".block-editor-block-list__block {core/image aligned left or right}": 21,
// The flotaed blocks should be higher than regular blocks
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// The flotaed blocks should be higher than regular blocks
// The floated blocks should be higher than regular blocks

@cr0ybot
Copy link
Contributor

cr0ybot commented Mar 16, 2020

While I agree that "alignwide" and such doesn't make much sense to us as it's not an actual alignment per se, the simplified approach to left/center/right/wide/full makes sense (to me) from a user experience perspective. As long as these align/position states all continue to exist within one dropdown/group and are mutually exclusive, I think works well. After all, if alignments are split from width settings while both being simultaneously available (I'm not sure anyone here is arguing for this anyways), is there a visual distinction between full-width vs align-left + full-width? Do some of these controls become disabled if incompatible align/width states have been applied?

However this more sophisticate approach is implemented, I'd love to see better global and block-specific settings (including built-in blocks) for theme developers for enabling/disabling certain alignment/position states. As discussed above, a theme can take any number of approaches for handling content with and wide/full alignments, which may be incompatible with a traditional "float" or other such specific alignment options.

@ZebulanStanphill proposed distinguishing between align left/right and float left/right, but honestly I wonder if that distinction is relevant or necessary to the user. More complex layouts can be achieved already with the columns block if a certain block is not aligning the way the user wants. What I guess I'm advocating for is that the left/right alignments be handled by the block/theme context, whether that's an actual CSS float or an auto margin or flex-item justify-self/align-self, etc. If a distinction should be made for the icon itself then perhaps that's a point in favor of having both float & align classes with block and global configuration that decides which are available. But ultimately, I think it's important to step back and consider if additional options are relevant for the user and if they need to know how the alignment is working under the hood.

@ZebulanStanphill
Copy link
Member

Yeah, I'm only suggesting that the options be individually named better; it still makes sense to keep them all in the same toolbar as they are all mutually exclusive.

There have definitely been occasions where I wanted to right-align (as in actual align) an image, and the default alignment (left unless the site is RTL) is pretty useful anyway, so I think it would be a good idea to add both as proper options. Making the actual left alignment option explicitly available (rather than just implicitly) would also be useful for cases where the default alignment is center.

@paaljoachim
Copy link
Contributor

I replied to a question on the Gutenberg plugin support forum. In relation to it I made this issue: #20941

Bottom line: User had a problem finding out how to use a kind of normal alignment for the Media & Text block. I told him that he had to turn off the default wide/full alignment.

@ZebulanStanphill
Copy link
Member

Yeah, it's not entirely clear at first that you have to deselect the selected option to get the default alignment. Even without adding explicit left/right (actual) alignment options, an "Auto"/"Default" option explicitly listed in the dropdown could be nice (or necessary if the dropdown became a radio control).

@youknowriad
Copy link
Contributor Author

Closing this PR. It is clear to me that the new direction for alignments should be declarative (InnerBlocks config) and offer different possibilities (regular, flex, grid using the layout prop).

@youknowriad youknowriad closed this Dec 9, 2020
@youknowriad youknowriad deleted the update/refactor-alignment-margin branch December 9, 2020 08:02
@paaljoachim
Copy link
Contributor

Just bringing this out there as we are talking about various kinds of alignments here.
How should we handle Image block caption alignment? As it aligns to the grid/focus/border around the image and not the image itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants