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

Block Styles: Reducing specificity of default block style variation styles #61268

Open
aaronrobertshaw opened this issue May 1, 2024 · 1 comment · May be fixed by #61032
Open

Block Styles: Reducing specificity of default block style variation styles #61268

aaronrobertshaw opened this issue May 1, 2024 · 1 comment · May be fixed by #61032
Labels
[Block] Buttons Affects the Buttons Block [Feature] Block Styles Issues or PRs that are related to the `register_block_style` API [Type] Enhancement A suggestion for improvement.

Comments

@aaronrobertshaw
Copy link
Contributor

Part of: #57537

Note: This is a blocker for the extended block style variations feature and section styling.

Problem

To support applying block style variations in a nested fashion, the specificity of block style variation selectors needs to be 0-0-0.

The Button block's stylesheet includes some default styles for the Outline block style variation to make its background transparent. If the selector for the Outline style's transparent background is reduced to zero it gets overridden by any button element or Button block styles in global styles.

This is due to the current style load order which is:

  1. block library styles including defaults for block style variations,
  2. global styles,
  3. and finally in #57908 stylesheets for the application of block style variations.

Additional context can be found in #61032 (comment).

Potential Solutions

The ideal order of styles here would be:

  1. Block library styles
  2. Global Styles
  3. Defaults for block style variations e.g. Button Outline's transparent background
  4. Block style variation styles

To achieve this, adding support for a new stylesheet for blocks would be beneficial. Perhaps something like variations.scss for block library blocks which can then be collected and enqueued in the appropriate order.

Alternative Option

One long term alternative could be to extend the styles property within the block.json API to allow them to define styles for block style variations. This would allow for dynamically generating these default styles for variations and outputting them when and if they make sense.

This dynamic approach however might not be a silver bullet solution given the potential for style variations to need styling that theme.json does not yet support. It would also need extra work to ensure compatibility across classic and block themes.

@aaronrobertshaw aaronrobertshaw added [Type] Enhancement A suggestion for improvement. [Block] Buttons Affects the Buttons Block [Feature] Block Styles Issues or PRs that are related to the `register_block_style` API labels May 1, 2024
@aaronrobertshaw
Copy link
Contributor Author

Through further exploration, the best compromise option for WP6.6 appears to be:

  • Keeping the variation styles that are already within the block library so they are still present for classic themes
  • Adding the variation styles to the base theme.json so they are then not overridden by block type/element styles from theme.json/global styles

This approach has been implemented within #61032.

Long term, the alternate option of extending the block.json styles so they are compatible with classic themes too is probably the best bet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Buttons Affects the Buttons Block [Feature] Block Styles Issues or PRs that are related to the `register_block_style` API [Type] Enhancement A suggestion for improvement.
Projects
Status: 🗣️ In Discussion / Needs Decision
Development

Successfully merging a pull request may close this issue.

1 participant