Skip to content

Fix: Allow style variations to override blockGap#74513

Closed
BrajamohanDas-afk wants to merge 26 commits intoWordPress:trunkfrom
BrajamohanDas-afk:Fix-Global-blockGap-property
Closed

Fix: Allow style variations to override blockGap#74513
BrajamohanDas-afk wants to merge 26 commits intoWordPress:trunkfrom
BrajamohanDas-afk:Fix-Global-blockGap-property

Conversation

@BrajamohanDas-afk
Copy link

What?

Fixes style variations being unable to override the blockGap property for blocks.

Closes #72318

Why?

Currently, block style variations can successfully override visual properties like background colors, but fail to override layout spacing properties like blockGap. This is because the layout engine calculates spacing values before style variation data is considered.

This creates an inconsistent developer experience where some style variation properties work while others are silently ignored.

How?

Added a check in lib/block-supports/layout.php to retrieve blockGap from active style variations before falling back to block-level or global values.

The fix implements the correct priority order:

  1. Style variation blockGap
  2. Block-level blockGap
  3. Global theme.json blockGap

Testing Instructions

  1. Create a theme with theme.json containing:
{
  "styles": {
    "spacing": { "blockGap": "50px" }
  }
}

2.Create a style variation file in styles/no-gap.json:

{
  "version": 3,
  "slug": "no-gap",
  "blockTypes": ["core/group"],
  "styles": {
    "spacing": { "blockGap": "0" },
    "color": { "background": "#ff0000" }
  }
}

3.Create a new post/page with two Group blocks
4.Add paragraphs inside each Group
5.Apply the "No Gap" style variation to the second Group
6.View the page on the frontend

Before this fix: Second group has red background but still 50px spacing.

brave_cryKRKw6fw

After: First group has 5px spacing, second group has blue background with 50px spacing.

brave_5neIgXdVmz

@github-actions
Copy link

github-actions bot commented Jan 10, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @Ndimande-dev, @hrishikesh2810, @EldarAgalarov.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: Ndimande-dev, hrishikesh2810, EldarAgalarov.

Co-authored-by: BrajamohanDas-afk <brajdas0022@git.wordpress.org>
Co-authored-by: SainathPoojary <sainathpoojary@git.wordpress.org>
Co-authored-by: SirLouen <sirlouen@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: shimotmk <shimotomoki@git.wordpress.org>
Co-authored-by: rutviksavsani <rutviksavsani@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: dimitrop <dimitro@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
Co-authored-by: harshbhonsle <harshbhonsle08@git.wordpress.org>
Co-authored-by: AtharvaSagane <atharvasagane@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jan 10, 2026
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @BrajamohanDas-afk! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Feature] Block Style Variations Issues or PRs that are related to the style variations for blocks [Feature] Layout Layout block support, its UI controls, and style output. labels Jan 11, 2026
BrajamohanDas-afk and others added 5 commits January 11, 2026 14:53
…pt (#70523)

Co-authored-by: SainathPoojary <sainathpoojary@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Refactoring the dom-ready package tests by replacing a custom MockDocument interface and direct property assignments with a simpler Object.defineProperty approach to mock the document's readyState property.

----------

Co-authored-by: SirLouen <sirlouen@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
* Add all fields to the block fields form by default

* Adjust appearance in patterns, only show first field and use a non-block title for standalone blocks

* Add comment

* Hide dropdown for non-collapsed mode

* Add doc block comment for BlockFields component

* Fix typo

----

Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
@tellthemachines
Copy link
Contributor

Thanks for the PR!

I'm not convinced this is the correct approach though. Block style variations should be output by gutenberg_render_block_style_variation_support_styles and not as part of individual block supports. In practical terms this means that instead of the block gap style being attached to the block's layout classname, e.g. .wp-container-core-group-is-layout-6c531013, it should instead be attached to the variation classname, e.g. is-style-no-gap.

The main reason this doesn't work out of the box is that gap isn't part of PROPERTIES_METADATA that is iterated through when computing the styles for variations, and it isn't output by get_layout_styles either because the node has a different shape to what's expected here.

I put together a draft alternative solution in #74529. I'm not 100% sure that's the best approach either 😅 but hopefully it's a start in the right direction (fixing this in the style variation logic itself, instead of the layout logic)

@BrajamohanDas-afk
Copy link
Author

@tellthemachines Okay, I’ll go through your approach and then modify the PR.

shimotmk and others added 14 commits January 12, 2026 16:45
Co-authored-by: shimotmk <shimotomoki@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: rutviksavsani <rutviksavsani@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
* Fully resolve some intra-package import paths

* Add changelog entry

Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org>
* Storybook: Fix introduction for source code link

* Fix description of site structure

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
Co-authored-by: shimotmk <shimotomoki@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
* Revert "`@wordpress/ui` `Button`: add `destructive` tone (#74463)"

This reverts commit d190fc7.

* Keep some better docs

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Unlinked contributors: Ndimande-dev.
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Unlinked contributors: dimitrop.
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
* Refactor from ariakit to base ui button component

* Remove button link storybook example

* CHANGELOG

* Use internal ComponentProps type utility

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
@github-actions github-actions bot added [Package] Date /packages/date [Package] DOM ready /packages/dom-ready [Package] Compose /packages/compose [Package] Core data /packages/core-data [Package] Components /packages/components [Package] Blocks /packages/blocks [Package] Editor /packages/editor [Package] Block library /packages/block-library [Package] Notices /packages/notices [Package] Block editor /packages/block-editor [Package] Edit Site /packages/edit-site [Package] DataViews /packages/dataviews [Package] Fields /packages/fields labels Jan 12, 2026
@BrajamohanDas-afk
Copy link
Author

@tellthemachines

Implementation the new approch: following the direction in #74529

1. PHP: Enable blockGap Setting for Variations

Add to the $config array:

$config = array(
    'version'  => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
    'settings' => array(
        'spacing' => array(
            'blockGap' => true, 
        ),
    ),
    'styles'   => array(
        'elements' => $elements_data,
        'blocks'   => $blocks_data,
    ),
);

2. PHP: Process Gap as Protected Property

2a) Update PROTECTED_PROPERTIES

const PROTECTED_PROPERTIES = array(
    'gap' => array( 'spacing', 'blockGap' ),
);

2b) Add a parameter to compute_style_properties()

Find the method signature:

protected static function compute_style_properties( $styles, $settings = array(), $properties = null, $theme_json = null, $selector = null, $use_root_padding = null ) {

Change to:

protected static function compute_style_properties( $styles, $settings = array(), $properties = null, $theme_json = null, $selector = null, $use_root_padding = null, $include_protected_properties = false ) {

2c) Merge protected properties into $properties when requested

Add this block after $properties is initialized (i.e., after the code that sets $properties to static::PROPERTIES_METADATA or equivalent):

if ( $include_protected_properties ) {
    foreach ( static::PROTECTED_PROPERTIES as $key => $value_path ) {
        if ( ! isset( $properties[ $key ] ) ) {
            $properties[ $key ] = $value_path;
        }
    }
}

2d) Pass true when generating style-variation declarations

Find the call that computes declarations for style variations, and change it to pass true as the last argument:

$style_variation_declarations[ $selector ] = static::compute_style_properties(
    $style_variation_node,
    $settings,
    null,
    $this->theme_json,
    null,
    null,
    true
);

3. JavaScript: Register Gap Property for Editor

Add to __EXPERIMENTAL_STYLE_PROPERTY:

gap: {
    value: [ 'spacing', 'blockGap' ],
    support: [ 'spacing', 'blockGap' ],
},

@BrajamohanDas-afk
Copy link
Author

If this is ok then, i will go with the pr.

- `AnglePickerControl`: Migrate styles from Emotion to a CSS module ([#73786](https://github.com/WordPress/gutenberg/pull/73786)).
- `Menu`: Clean up popover wrappers ([#74207](https://github.com/WordPress/gutenberg/pull/74207)).
- `Button`, `DateCalendar`, `DateRangeCalendar`, `CheckboxControl`, `Panel`, `Placeholder`: Remove outdated vendor prefix properties in CSS ([#74213](https://github.com/WordPress/gutenberg/pull/74213)).
- Updated `fast-deep-equal` imports for compatibility with strict Node.js resolution ([#74530](https://github.com/WordPress/gutenberg/pull/74530)).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure that all CHANGELOG entries are kept in the "Unreleased" section, at the top of the file

@t-hamano
Copy link
Contributor

It looks like there are a lot of unnecessary commits, probably due to a failed rebase or merge 😄 It might be better to close this PR and move forward with #74529.

Thanks for your efforts, @BrajamohanDas-afk! If you don't mind, I'd be happy if you could test #74529.

@t-hamano t-hamano closed this Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Block Style Variations Issues or PRs that are related to the style variations for blocks [Feature] Layout Layout block support, its UI controls, and style output. First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block editor /packages/block-editor [Package] Block library /packages/block-library [Package] Blocks /packages/blocks [Package] Components /packages/components [Package] Compose /packages/compose [Package] Core data /packages/core-data [Package] DataViews /packages/dataviews [Package] Date /packages/date [Package] DOM ready /packages/dom-ready [Package] Edit Site /packages/edit-site [Package] Editor /packages/editor [Package] Fields /packages/fields [Package] Notices /packages/notices [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global blockGap property is not overridable in style variations