Skip to content

Commit

Permalink
Adjust selectors so that > :first-child/> :last-child still has 0…
Browse files Browse the repository at this point in the history
…,2,0 specificity to override theme.json spacing
  • Loading branch information
talldan committed Jul 31, 2024
1 parent b107932 commit c11746d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
32 changes: 14 additions & 18 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,7 @@ function gutenberg_get_layout_definitions() {
),
),
),
// First/last child rules need to be after `> *` rule to take
// precedence when they have the same specificity.
'spacingStyles' => array(
array(
'selector' => ' > *',
'rules' => array(
'margin-block-start' => null,
'margin-block-end' => '0',
),
),
array(
'selector' => ' > :first-child',
'rules' => array(
Expand All @@ -67,6 +58,13 @@ function gutenberg_get_layout_definitions() {
'margin-block-end' => '0',
),
),
array(
'selector' => ' > *',
'rules' => array(
'margin-block-start' => null,
'margin-block-end' => '0',
),
),
),
),
'constrained' => array(
Expand Down Expand Up @@ -112,16 +110,7 @@ function gutenberg_get_layout_definitions() {
),
),
),
// First/last child rules need to be after `> *` rule to take
// precedence when they have the same specificity.
'spacingStyles' => array(
array(
'selector' => ' > *',
'rules' => array(
'margin-block-start' => null,
'margin-block-end' => '0',
),
),
array(
'selector' => ' > :first-child',
'rules' => array(
Expand All @@ -134,6 +123,13 @@ function gutenberg_get_layout_definitions() {
'margin-block-end' => '0',
),
),
array(
'selector' => ' > *',
'rules' => array(
'margin-block-start' => null,
'margin-block-end' => '0',
),
),
),
),
'flex' => array(
Expand Down
2 changes: 1 addition & 1 deletion lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ protected function get_layout_styles( $block_metadata, $types = array() ) {
$spacing_rule['selector']
);
} else {
$format = static::ROOT_BLOCK_SELECTOR === $selector ? ':root :where(.%2$s %3$s)' : ':root :where(%1$s-%2$s %3$s)';
$format = static::ROOT_BLOCK_SELECTOR === $selector ? ':root :where(.%2$s)%3$s' : ':root :where(%1$s-%2$s)%3$s';
$layout_selector = sprintf(
$format,
$selector,
Expand Down

0 comments on commit c11746d

Please sign in to comment.