Skip to content

Expanding and simplifying layout #42385

Open

Description

@SaxonF

What problem does this address?

When making a decision around how to implement a particular layout, multiple blocks need to be considered. There is group, columns, layout grid, row and stack, not to mention more specific blocks like cover and gallery. The tools within those blocks also limit what's possible, particularly when looking at inner block sizes and alignment

What is your proposed solution?

This proposal consists of a few changes revolving around creating a single container block that can handle both fluid and grid based layouts, as well as extending layout/size controls.

A single container block

As a user, I can currently implement a two column layout using either the Columns, Layout Grid or Row blocks. They each behave slightly different but they also overlap slightly in what you can accomplish. It's worth exploring whether we can accomplish all behaviours using a single intuitive block.

POC

I have built a little proof of concept that I would recommend playing with https://s75qk3.csb.app

You can also see a quick demo below:

layout-demo.mp4
  • By default columns snap to a 12 column grid
  • Columns are either in a "fill" state (take up remaining space) or have a set column width
  • In the POC if you hold cmd while dragging a column you break out of the grid
  • Snap to grid resizes columns to the nearest column size

The block

What would this look like in the block inspector?

The container block would have the following global layout settings:

  • Direction [horizontal, vertical]
  • Gap/Block Spacing which is driven by spacing scale in theme.json
  • Alignment which is a combination of the existing justification controls + the opposite axis e.g. align-items when set to row. The grid is arguably a more intuitive way of justification/alignment content within a container.

All child blocks of a container block have size properties accessible to them, starting with width but also including padding and margin.

An important point to note is that there should be a global token called size/layout/width which is an array or object of width values. wide and content (default) would be two options, but you should be able to create as many as you like.

Layout and size controls will change depending on the direction of the container block.

Horizontal

Container
image

Containers set to horizontal direction also have an inner block width setting which contains a snap to grid toggle and wrap items toggle. The snap to grid toggle performs the same function as seen in the POC above.

Child
image

  • Width can be set to
    • Fill which is basically flex grow 1
    • Fit which is flex grow 0
    • Fixed which sets a fixed width depending on the unit type selected
      • Columns which is only accessible when "snap to grid" is enabled. If a fixed width is set on a child block, the parent block snap to grid is toggled off. If toggled back on, all child blocks scale to their nearest column value.
      • Theme which pulls width values from a size/width/layout scale set in global settings (see above note)
      • px/%/etc which are just hard coded values
  • Height which lets the child either fill the height of the row (alignItems: stretch) or fit (default) its contents

Vertical

Container
When a container block is set to vertical orientation it behaves like the existing group block by default. The only change here is that we are removing the existing (and somewhat confusing) Inner blocks use full width setting and relying on smart defaults. If a container block is wider than the content width/layout size, then inner block widths should be set to the content width, if its smaller than they should be set to "fill". The size controls should be accessible to all inner blocks however.

image

Alternatively, we can introduce an default inner block width setting which uses the same interactions as the width setting of any other block. The only thing you can't accomplish with this interaction is setting the "wide" size of child blocks but I'd argue this should be set on the child anyway.

image

Child
A child within a vertical direction container block has its width set to fill by default, unless the container block is wider than the content width. It also has its horizontal padding set to the global padding setting. If a user wanted an image to span the full width of the container, they just need to remove the padding (or could be margin).

The width setting has an extra full option which is essentially 100vw.

image

These settings should be able to be applied on any container block, including blocks like PostContent. This gives the theme builder more flexibility when designing unique templates.

For added flexibility we should also consider adopting a negative margin property that also uses global spacing values.

Activity

  1. SaxonF commented on Jul 13, 2022

    @SaxonF
    ContributorAuthor

    This issue touches on some of the concepts discussed in #36082 and #35607 and #42085

  2. jameskoster commented on Jul 13, 2022

    @jameskoster
    Contributor

    Big +1 from me on the idea of abstracting layout as a concept versus dedicated blocks like row/columns/group. I'm curious about the relationship with semantic blocks that require layout... things like navigation, social links, gallery. My assumption is that they would just 'support' layout, and users would find the same panel when working with those blocks.

    How do you see fixed columns working on nested containers?

    I appreciate most of the examples here are to demonstrate full capabilities, but it could be good to ideate on the smart defaults and determine the minimum number of controls to expose by default so that we might avoid an overwhelming initial experience.

    Nice work. This is very comprehensive :)

  3. added
    [Type] Enhancement
    [Feature] Blocks
    [Feature] Design Tools
    and removed
    [Feature] Blocks
    on Jul 13, 2022
  4. andrewserong commented on Jul 14, 2022

    @andrewserong
    Contributor

    Fascinating exploration, thanks for sharing the great interactive demo, too!

    This proposal consists of a few changes revolving around creating a single container block

    For a bit of context surrounding the Group, Row, and Stack blocks — they're all the one Group block, but use the block variations API to be exposed as different conceptual blocks in the editor, based on their layout settings. At the moment the Group block appears to be the canonical container block in the editor, and it gets registered as such when the editor boots up.

    So, (at least in API terms), we already have a Layout concept that's abstracted away from the block type itself, where different features of Layout can be opted-into at the block.json level. The Group block opts-in to (nearly) everything, and the variations can be thought of as a kind of preset for Layout settings. For example, if you take a Row block and switch the orientation to vertical it looks like it transforms it to a Stack block, but really it's still just a group block with a particular Layout setting. Here's how the Stack variation exists when serialized to markup:

    <!-- wp:group {"layout":{"type":"flex","flexWrap":"nowrap","orientation":"vertical"}} -->
    <div class="wp-block-group"></div>
    <!-- /wp:group -->
    

    With that in mind, it sounds like there are a few different parts to this proposal: 1) The changes to controls and which ones appear in the Layout panel, 2) the introduction of a Grid layout type, that is different to the existing flow and flex layout types, and 3) the ability to resize children of the Grid layout type to determine a particular grid layout?

    To achieve this, if there was an additional Grid layout type, it could then be exposed in the editor as a Grid variation of the Group block, too. That way, users could switch a Group block from a default flow layout to Grid or back, either via the existing Variations toggles, a new UI for switching between Layout types, or by adjusting Layout settings?

    When it comes to the existing conceptual blocks like Group and Row, some of the benefits of keeping some semantic difference in block naming within the editor (even if behind-the-scenes they're still a Group block) include:

    • A user who wants two or more blocks to be on the same row, but otherwise isn't concerned with layout per-se — e.g. I've got a site title and a site logo that I want to put into a header, so I reach for the "Row" block. Or, I "group" them, and then switch the Group to a Row.
    • A user who wants to group together two or more blocks within a blog post as a call-out or aside — e.g. I've got a bit of explanatory text, so I'll highlight a header plus a couple of paragraphs, click the Group button, then add a border and a background colour so it looks more like a callout.

    All child blocks of a container block have size properties accessible to them, starting with width but also including padding and margin.

    I really like the idea of the child blocks being able to set their width or column span — one of the things that'd be very cool, is if it could also be supported in the Gallery block, so that users could set a grid of images, and then select particular images to span multiple columns, to have a customisable mosaic kind of layout.

    Width can be set to
    Fill which is basically flex grow 1
    Fit which is flex grow 0

    For these kinds of layout options, did you have in mind that the layout controls are defining a flexbox layout or CSS grid approach?

  5. tellthemachines commented on Jul 14, 2022

    @tellthemachines
    Contributor

    Thanks for sharing these thoughts!

    One thing we need to account for is responsive behaviour. In the current Columns block, that manifests as a “Stack on mobile” setting, but also in the ability to set fixed widths in px units, and unset width altogether so that a column can take up the remaining space. This allows us, for example, to build classic fixed sidebar/responsive content area layouts.

    By default columns snap to a 12 column grid
    Columns are either in a "fill" state (take up remaining space) or have a set column width

    I’m curious about how the 12-col underlying grid would work in a mixed fixed/variable column width context. Is the grid always 12-col regardless of screen size? Do fixed px width columns ignore it?

  6. eric-michel commented on Jul 19, 2022

    @eric-michel

    This is a very cool demonstration! I love the sandbox to allow for testing of the features!

    One thing we need to account for is responsive behaviour. In the current Columns block, that manifests as a “Stack on mobile” setting, but also in the ability to set fixed widths in px units, and unset width altogether so that a column can take up the remaining space. This allows us, for example, to build classic fixed sidebar/responsive content area layouts.

    This is what I'm immediately curious about as well. Right now, Gutenberg doesn't really have a lot of options for controlling how things will shift when the screen size shrinks. In any case where I want something even remotely complex (like 3 column shifting to 2/1 instead of 1/1/1) I usually swap to a row block and work up some custom CSS.

  7. added
    [Feature] Layout
    on Oct 5, 2022
  8. SaxonF commented on Mar 30, 2023

    @SaxonF
    ContributorAuthor

    I've spent more time thinking this through and have iterated on the above to get to the point below.

    image

    Consistent layout and dimension settings for all container blocks (e.g. Group or even Query) and child blocks. We infer whether a block is flex, grid or auto based on its settings, and in some cases its children's settings. We also infer the "inner block width" toggle based on child width setting and hide the complex wide/content width setting unless it's needed.

  9. jasmussen commented on Mar 30, 2023

    @jasmussen
    Contributor

    I always appreciate how deep you immerse yourself in the UI/UX challenges, Saxon. Nice work.

    I am having a bit of a hard time extracting the Layout pieces on their own from the component and inspector changes you made. I understand why the compression of said componentry might have played a role in your decisions, but it can still make it a little trickier to compare with what's shipping, since the visual delta is bigger.

    Two riffs on your mockup, just to see if I understand this right:

    Option 1

    Option 2

  10. SaxonF commented on Mar 30, 2023

    @SaxonF
    ContributorAuthor

    @jasmussen that looks about right. There is an experimental branch in motion here which we will use to play with some of these changes.

  11. jasmussen commented on Mar 31, 2023

    @jasmussen
    Contributor

    Nice, I took the branch for a spin and left some comments there.

  12. richtabor commented on May 10, 2023

    @richtabor
    Member

    I explored a little on this front too, mostly figuring a way to fuse what we have today with a bit more simplicity - but also flexibility.

    CleanShot.2023-05-10.at.10.50.33.mp4

    Align/Justify Matrix

    Like @jameskoster explored in #49448, I think we could potentially condense a bit, while adding more flexibility, with a matrix control like what Figma uses.

    Justify (Distribute) Select

    A way to set values for how the blocks are distributed within the layout. I.e. Space between, around and evenly. We only support between at the moment, but using a select lets us flex this without making the UI more complicated.

    I'm not 100% on the label—could be "Distribution" or "Distribute" or "Space" (though we do have Block Spacing elsewhere).

    Nested width

    A way to condense the current layout content controls that exist within the Group block.

    • Instead of always showing the content/wide input fields, leverage the existing settings icon pattern to reveal additional controls.
    • Uses a ToggleGroup to name the options, instead of a toggle to turn on one of the modes (which is confusing).
    • Use relative help text based on the value.
    • If there are custom content/wide input values, the layout attribute is set to "constrained".
    • This proposes layout constraining for the Stack block, as the Group block is basically a less malleable Stack block—but the Stack currently lacks support for the width, so you have to use the Group if you need that. This would pave the way for using the Stack consistently instead of having to decide if you need a Group or Stack.
    • Also not 100% on the label, but it could work.
  13. 28 remaining items

  14. mtias commented on Aug 10, 2023

    @mtias
    Member

    @tellthemachines it's ok to reflect orientation as a layout attribute, what I mean is it should not imply relocating the variation functions into layout as well. Variations are higher level for group(s) block. We use them for transforms; in multi-select; in list view; we expose them in the inserter. They offer a direct mental model to things you can express with layout without understanding the intricacies of layout properties. I consider this an important user-focused design principle. Other blocks leveraging the layout tools (buttons, social icons, navigation) are fine to just rely on orientation since the mental model and context is a bit different there.

  15. SaxonF commented on Aug 10, 2023

    @SaxonF
    ContributorAuthor

    it's ok to reflect orientation as a layout attribute, what I mean is it should not imply relocating the variation functions into layout as well

    @mtias Could you clarify what you mean here in terms of what sort of experience you expect? It sounds like you're fine with option #2 @tellthemachines mentioned above. The fact that we currently have an orientation control that changes the group variation also breaks hierarchy in a way (from a users perspective).

    Other blocks leveraging the layout tools (buttons, social icons, navigation) are fine to just rely on orientation since the mental model and context is a bit different there.

    I don't think our mental model as developers would match that of end users. I doubt majority of users even know what a block variation is. If we were to go with this approach I'd expect variation icons and orientation/direction icons to be the same.

  16. richtabor commented on Aug 10, 2023

    @richtabor
    Member

    I am not sure if moving the dimensions from the "Styles" Tab to the "Settings" Tab. I prefer having control over background color, padding and border all at once.
    I am using a theme with custom spacing presets (like #52827), therefore I'd also prefer if "Gap" would be full width. Supports also the argument with long translations.

    Just explorations; many more bits to iron out. :)

  17. mtias commented on Aug 11, 2023

    @mtias
    Member

    @SaxonF the main experience I expect is to preserve the mental model afforded by blocks more than the mental model of properties. I think the latter is the developer and systematic thinking in us more than what users would intuitively understand. So I want us to balance improving design tools with the value of blocks as the primary user-facing abstraction. In a nutshell, I rather normal users learn one thing—blocks—than a whole set of layout tools.

    Another example: the Cover block can be seen as just a group block with a given set of properties. However, a user would have a much easier time discovering a Cover in the inserter than figuring out a Group can do all the things they need it to do to replicate a cover. It doesn't matter if we end up with Cover being just a variation of Group, what matters is users recognize and interact with it through all our major interfaces (inserter, transforms, list view). The block encapsulates an intention and communicates it much more rapidly than properties.

    Block variations were designed to allow us to have both things—a consistent set of malleable properties that allows us to reduce duplication and consolidate tools without letting go of the more direct aspect of the block mental model. I don't mind layout orientation existing as a property, what I mind is burying blocks within it and eliminating the higher level concept of quick variations from the inserter.

    So in terms of the proposals above I'm actually fine with orientation existing in layout tools with the arrows and for group blocks to also see that reflected in the variations. Which I guess is what we have now.

    The fact that we currently have an orientation control that changes the group variation also breaks hierarchy in a way (from a users perspective)

    I don't think it does. We have blocks where a given combination of attributes would match a variation and the variation become enabled. Variations can be seen as a shortcut for a combination of attributes but it's not a requirement that a user understands this. If anything, I think changing layout orientation and seeing my Stack became a Row helps me understand things better.

  18. SaxonF commented on Sep 18, 2023

    @SaxonF
    ContributorAuthor

    An update here is that we have a second prototype branch here. I'd recommend trying it by attempting to reproduce common pattern layouts etc. If you're used to the existing layout controls it takes a bit to adjust but I personally find it a little easier to understand conceptually and the addition of predictable height/width controls goes a long way.

    This obviously wont make it for 6.4 but I'm hoping to put together a few tests to send out to different groups of people to collect feedback and iterate before 6.5.

  19. moved this to In Progress in Design prioritieson Dec 7, 2023
  20. tellisbethel commented on Dec 7, 2023

    @tellisbethel

    Howdy! It was recommended I share a recent scenario where I ran into some difficulties helping a user with a layout request:

    A user wanted to have a “Welcome to our team” Cover block banner show Full width above their footer on their About Us page, while maintaining the rest of their page content at Wide width. (The Content block in their Page template was already set to be Wide width.)

    With lots of help, I almost nailed the request: I ended up with a Full width banner, but narrow, instead of wide, width content. We settled on suggesting the user try the Content block's Layout > Content width setting to let them set their ideal content width manually.

    Even though I have a much better grasp thanks to help from colleagues and my experimentation, it felt like a lot of effort for a simple request: place a full width banner beneath wide width content. Understanding where to apply the "Inner blocks use content width" setting is also tough, especially with several layers of nesting. That said, I do appreciate the power of FSE!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Design Tools[Feature] Layout[Type] Enhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions