Skip to content

More Block Tools and APIs for container blocks. #27324

@youknowriad

Description

@youknowriad

As we move forward with Full Site Editing, and explore adding customizations options to several blocks, we're starting to notice that the current APIs and interactions for container blocks are less than ideal. We might be missing some abstractions there to achieve several use-cases:

Layout

We have several blocks that are "flex containers". I'm thinking of columns, navigation, social icons, buttons. There are several common issues that are highlighted in these blocks:

  • They are all styled almost similarly: A flex container with children blocks that stack inner blocks one after the other.
  • Some of these blocks offer ways to define the "width" of their items.
  • Most of these blocks need to disable "alignments" for their children.

Yet, all these shared properties are implemented in an Adhoc way. Styles are duplicated, width config is duplicated, ...

Alignments

This is particularly visible for FSE themes but it's a global issue. When you add a container (group block or a column block), sometimes the area is too narrow and you don't want the same alignments options available at the global level to apply. Also, if different areas of a page/template/content can have different kind of alignments (think sidebar, content area), how does a user "define" what alignments are available inside this area? How to avoid the "global alignments" styles to apply?

Nesting

This is another issue that is particularly visible in FSE but may exist elsewhere. Take a look at this screenshot.

Screenshot 2020-10-30 at 12 23 30

On the side, you can see the hierarchy of the page. One thing that stands out is that there's a deep level of nesting where sometimes it might not be needed. Why the first column is not directly the "single post" template part and the second ne not the "sidebar" template part. Why do we need intermediary blocks (column) while a template part is a simple container just like column and could just replace it in some cases.

Customizations

This is another important use-case that we're starting to see as we add customization options.

  • How do I change all the colors of the buttons in the "buttons" block at once? Why should I have to go to each block to apply the change? and should we store this at the leaf level or at the container level, or both?
  • A lot of users are confused about alignments there, when they add a "buttons" block, the child "button" block gets selected and it's not obvious how to align the buttons (select the parent and then align).

This raises the question of surfacing common customization tools for children in the parent block and the opposite too, how to surface the parent options in the children (or if we should surface them).

--
These are some of the challenges we're facing now and solving them would improve the experience greatly.

Potential solutions

1- To solve the layout and alignment issues, I started introducing the "layout" prop to "InnerBlocks". For now, it's almost an empty bucket but the goal is that applying a given layout type to a container automatically adds the styling and the positionning and common options to their child blocks. For instance, if I set the "buttons" container as a "flex" layout, automatically, it will get a classname to style it properly and its children blocks will see the regular alignments being disabled and a "position" attribute added where you can customize the position of the child block in that particular context (for instance set a width). This same abstraction ("layout") could allow us to solve the FSE issue of defining alignments for given areas. For instance we could imagine a "grid" layout where could have ways to define "wide"/"full"/"center"/"side" alignments using grid configs and have these styles generated automatically for the containers and also available for the child blocks (saved in the "position" attribute).

2- For the solution to surface controls between parent and child blocks, we do have an experimental way of doing that but it's not ideal. I'd love some design explorations there before trying to come up with the best abstraction.

--
cc @WordPress/gutenberg-core @aristath @vindl @jameskoster @kjellr @scruffian

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrameworkIssues related to broader framework topics, especially as it relates to javascriptNeeds DesignNeeds design efforts.[Feature] Block APIAPI that allows to express the block paradigm.[Type] DiscussionFor issues that are high-level and not yet ready to implement.

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions