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

Layout: Reduce specificity of fallback blockGap styles #42665

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ protected function get_layout_styles( $block_metadata ) {
if ( $block_gap_value ) {
foreach ( $layout_definitions as $layout_definition_key => $layout_definition ) {
// Allow skipping default layout for themes that opt-in to block styles, but opt-out of blockGap.
if ( ! $has_block_gap_support && 'default' === $layout_definition_key ) {
if ( ! $has_block_gap_support && 'flex' !== $layout_definition_key ) {
continue;
}

Expand Down Expand Up @@ -1324,14 +1324,25 @@ protected function get_layout_styles( $block_metadata ) {
}
}

$format = static::ROOT_BLOCK_SELECTOR === $selector ? '%s .%s%s' : '%s.%s%s';
$layout_selector = sprintf(
$format,
$selector,
$class_name,
$spacing_rule['selector']
);
$block_rules .= static::to_ruleset( $layout_selector, $declarations );
if ( ! $has_block_gap_support ) {
// For fallback gap styles, use lower specificity, to ensure styles do not unintentionally override theme styles.
$format = static::ROOT_BLOCK_SELECTOR === $selector ? '%1$s :where(.%2$s%3$s)' : '%1$s%3$s';
$layout_selector = sprintf(
$format,
$selector,
$class_name,
$spacing_rule['selector']
);
} else {
$format = static::ROOT_BLOCK_SELECTOR === $selector ? '%s .%s%s' : '%s.%s%s';
$layout_selector = sprintf(
$format,
$selector,
$class_name,
$spacing_rule['selector']
);
}
$block_rules .= static::to_ruleset( $layout_selector, $declarations );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,28 @@ export function getLayoutStyles( {
}

if ( declarations.length ) {
const combinedSelector =
selector === ROOT_BLOCK_SELECTOR
? `${ selector } .${ className }${
spacingStyle?.selector || ''
}`
: `${ selector }.${ className }${
spacingStyle?.selector || ''
}`;
let combinedSelector = '';

if ( ! hasBlockGapSupport ) {
// For fallback gap styles, use lower specificity, to ensure styles do not unintentionally override theme styles.
combinedSelector =
selector === ROOT_BLOCK_SELECTOR
? `${ selector } :where( .${ className }${
spacingStyle?.selector || ''
})`
: `${ selector }${
spacingStyle?.selector || ''
}`;
} else {
combinedSelector =
selector === ROOT_BLOCK_SELECTOR
? `${ selector } .${ className }${
spacingStyle?.selector || ''
}`
: `${ selector }.${ className }${
spacingStyle?.selector || ''
}`;
}
ruleset += `${ combinedSelector } { ${ declarations.join(
'; '
) }; }`;
Expand Down