Blocks with ad-hoc UI controls, global styles, and patterns #28518
Labels
[Feature] Blocks
Overall functionality of blocks
Global Styles
Anything related to the broader Global Styles efforts, including Styles Engine and theme.json
[Status] In Progress
Tracking issues with work in progress
[Type] Discussion
For issues that are high-level and not yet ready to implement.
The recommended way to add styles to a block is via the block support mechanism. However, that's not enough for certain situations and blocks: blocks that want the UI control to update styles in an inner HTML element of the block, blocks that want the style to be coordinated in a number of properties.
One of the latest examples I've ran into was the search block. This effort has gone through some iterations:
While the block support mechanism is the recommended way to add support for styles, in this particular case the whole experience would be odd and it sounds like this block would benefit from a custom UI control. This isn't specific to the search block but we've ran into this with other blocks (IIRC, with the social links).
While some blocks may need ad-hoc controls for style properties, I see two issues with allowing them:
1. How those blocks can be styled (in a predictable way) via global styles?
At the global level (theme.json), we only allow style properties that are supported at the block level (supports object in block.json). Each block may declare support for a subset of all the style properties we support. The current mechanism we have attaches the styles to the wrapper node (block level) or outputs a single style rule for the block in a new stylesheet (global level).
Allowing ad-hoc UI controls that aren't "managed" by us, poses a few challenges:
Target inner markup: at the global level, the selector for the block could be anything. So,
core/search
in theme.json could be compiled to.wp-block-search .some-inner-class
in the resulting stylesheet. It departs a bit from what we've done so far that the generated block selector targets some inner markup. I think this should be evaluated block by block.Target many elements at once: we don't have a way to do this at the global level, there's a single style rule generated per block.
If custom blocks use style properties we don't support, we don't have info about what needs to be done at the global level.
2. How those blocks can be used in patterns?
To add style to patterns themes add inlines styles. Those inline styles need to be "managed" by the block support system. Blocks can't have any random property as inline styles, otherwise, they'll be invalidated because the style property can't be regenerated from the block's attributes. Example with a regular block:
style="text-shadow: 1px 1px 2px pink"
.So, if blocks use the supports mechanism they can have inline styles. However, for blocks that don't, what's the way forward to support patterns?
The text was updated successfully, but these errors were encountered: