-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Encode the heading block as block variations of h1-h6 elements #22805
Conversation
Size Change: +95 B (0%) Total Size: 1.11 MB
ℹ️ View Unchanged
|
I've been playing with the block variations API. Block variations are preset of block attributes. By design, there's no guarantee that two fields are in sync when the user makes changes (ex: changes a block from h2 to h3), that's not what the block variations API is about. Instead, it offers presets that can be exposed in two different contexts:
This exploration was driven by the question: can block variations absorb the dynamic nature of the block selectors (blocks that represent multiple HTML elements)? The answer seems to be that block selectors need a different thing: a mechanism to be synchronized with some other part of the block. In the case of core/heading, we want it to be synchronized with the level attribute: level is 1 => selector is h1, and so on. In the case of core/list, we want it to be synchronized with the ordered attribute: ordered is true => selector is ol, ordered is false => selector is ul. I'll close this and will open a different PR to explore how to achieve that synchronization. |
The above is not to say that blocks that represent many HTML elements won't benefit from block variations. Probably that's a worthy exploration anyway. What I'm saying is that the idea of "dynamic selectors" discussed at #22518 (comment) is orthogonal/independent from block variations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nosolosw,
By design, there's no guarantee that two fields are in sync when the user makes changes (ex: changes a block from h2 to h3)
The variations provide an initial set of attributes. These attributes may later be changed, changing the variation.
I guess to use variations we would need a way to say if the current block attributes match a variation. The mechanism could be as simple as compare the attributes of the block and verify if all of them are still equal to the variation.
This also seems to be the same that we need for global styles.
If we added this mechanism to variations e.g: a function that given a variation and the current attributes a block says if the block matches the variation, would variations work for global styles selector matching?
Related
Some blocks represent many HTML elements. Examples of this are the core/heading block (h1-h6) and the core/list block (ol, ul). The Block Style System needs to bind a block to a CSS selector. However, for these blocks, the selector they use depends on some other attribute values.
This PR explores whether the selector can be expressed as a field within a block variation in these cases.