Skip to content

Commit

Permalink
Fix block style selectors when root block selector is an element
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Jan 15, 2024
1 parent f092ad7 commit 15270b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1020,8 +1020,8 @@ protected static function get_blocks_metadata() {
foreach ( $registered_styles[ $block_name ] as $block_style ) {
if ( ! isset( $style_selectors[ $block_style['name'] ] ) ) {
$style_selectors[ $block_style['name'] ] = static::append_to_selector(
'.is-style-' . $block_style['name'],
$block_metadata['selector']
$block_metadata['selector'],
'.is-style-' . $block_style['name']
);
}
}
Expand Down Expand Up @@ -1065,14 +1065,14 @@ protected static function get_blocks_metadata() {
$style_selectors = array();
if ( ! empty( $block_type->styles ) ) {
foreach ( $block_type->styles as $style ) {
$style_selectors[ $style['name'] ] = static::append_to_selector( '.is-style-' . $style['name'], static::$blocks_metadata[ $block_name ]['selector'] );
$style_selectors[ $style['name'] ] = static::append_to_selector( static::$blocks_metadata[ $block_name ]['selector'], '.is-style-' . $style['name'] );
}
}

// Block style variations can be registered through the WP_Block_Styles_Registry as well as block.json.
$registered_styles = $style_registry->get_registered_styles_for_block( $block_name );
foreach ( $registered_styles as $style ) {
$style_selectors[ $style['name'] ] = static::append_to_selector( '.is-style-' . $style['name'], static::$blocks_metadata[ $block_name ]['selector'] );
$style_selectors[ $style['name'] ] = static::append_to_selector( static::$blocks_metadata[ $block_name ]['selector'], '.is-style-' . $style['name'] );
}

if ( ! empty( $style_selectors ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ export const getBlockSelectors = ( blockTypes, getBlockStyles ) => {
const styleVariationSelectors = {};

blockStyleVariations?.forEach( ( variation ) => {
const styleVariationSelector = `.is-style-${ variation.name }${ selector }`;
const styleVariationSelector = `${ selector }.is-style-${ variation.name }`;
styleVariationSelectors[ variation.name ] = styleVariationSelector;
} );

Expand Down

0 comments on commit 15270b6

Please sign in to comment.