Skip to content

Commit

Permalink
Fix: Theme.json application of custom root selector for styles
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Jan 23, 2024
1 parent 2997bad commit 957a22f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ protected static function get_blocks_metadata() {

if ( $duotone_support ) {
$root_selector = wp_get_block_css_selector( $block_type );
$duotone_selector = WP_Theme_JSON_Gutenberg::scope_selector( $root_selector, $duotone_support );
$duotone_selector = static::scope_selector( $root_selector, $duotone_support );
}
}

Expand Down Expand Up @@ -1185,7 +1185,7 @@ public function get_stylesheet( $types = array( 'variables', 'styles', 'presets'
$setting_nodes[ $root_settings_key ]['selector'] = $options['root_selector'];
}
if ( false !== $root_style_key ) {
$setting_nodes[ $root_style_key ]['selector'] = $options['root_selector'];
$style_nodes[ $root_style_key ]['selector'] = $options['root_selector'];
}
}

Expand Down
24 changes: 24 additions & 0 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2451,4 +2451,28 @@ public function test_resolve_variables() {
$this->assertEquals( $small_font, $styles['blocks']['core/quote']['variations']['plain']['typography']['fontSize'], 'Block variations: font-size' );
$this->assertEquals( $secondary_color, $styles['blocks']['core/quote']['variations']['plain']['color']['background'], 'Block variations: color' );
}

public function test_get_stylesheet_custom_root_selector() {
$theme_json = new WP_Theme_JSON_Gutenberg(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'styles' => array(
'color' => array(
'text' => 'teal',
),
),
),
'default'
);

$options = array( 'root_selector' => '.custom' );
$actual = $theme_json->get_stylesheet( array( 'styles' ), null, $options );

// Results also include root site blocks styles which hard code
// `body { margin: 0;}`.
$this->assertEquals(
'body { margin: 0;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.custom{color: teal;}',
$actual
);
}
}

0 comments on commit 957a22f

Please sign in to comment.