From 5c1be84b41ef553d0615a6581126a1f148963315 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Fri, 16 Feb 2024 15:06:24 +1000 Subject: [PATCH 1/3] Elements: Prevent block instance element styles overriding buttons --- lib/block-supports/elements.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/block-supports/elements.php b/lib/block-supports/elements.php index 85dbd7d39797c..a090912e0402c 100644 --- a/lib/block-supports/elements.php +++ b/lib/block-supports/elements.php @@ -142,8 +142,8 @@ function gutenberg_render_elements_support_styles( $pre_render, $block ) { 'skip' => $skip_button_color_serialization, ), 'link' => array( - 'selector' => ".$class_name a", - 'hover_selector' => ".$class_name a:hover", + 'selector' => ".$class_name a:not(.wp-element-button)", + 'hover_selector' => ".$class_name a:not(.wp-element-button):hover", 'skip' => $skip_link_color_serialization, ), 'heading' => array( From 52a2e9a68997ed6d95fe9f953c34396cdce4c88e Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Fri, 16 Feb 2024 15:10:56 +1000 Subject: [PATCH 2/3] Update unit tests for elements block support --- phpunit/block-supports/elements-test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpunit/block-supports/elements-test.php b/phpunit/block-supports/elements-test.php index efea11887b620..54411728e95cb 100644 --- a/phpunit/block-supports/elements-test.php +++ b/phpunit/block-supports/elements-test.php @@ -273,8 +273,8 @@ public function data_elements_block_support_styles() { ), ), ), - 'expected_styles' => '/^.wp-elements-[a-f0-9]{32} a' . $color_css_rules . - '.wp-elements-[a-f0-9]{32} a:hover' . $color_css_rules . '$/', + 'expected_styles' => '/^.wp-elements-[a-f0-9]{32} a:not\(.wp-element-button\)' . $color_css_rules . + '.wp-elements-[a-f0-9]{32} a:not\(.wp-element-button\):hover' . $color_css_rules . '$/', ), 'generic heading element styles are applied' => array( 'color_settings' => array( 'heading' => true ), From dc898bb7bc6a64eb6d28281a200845268b3bdcc3 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Fri, 16 Feb 2024 15:24:18 +1000 Subject: [PATCH 3/3] Make selector include the where to be fully consistent with theme.json --- lib/block-supports/elements.php | 5 +++-- phpunit/block-supports/elements-test.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/block-supports/elements.php b/lib/block-supports/elements.php index a090912e0402c..89275830f64b2 100644 --- a/lib/block-supports/elements.php +++ b/lib/block-supports/elements.php @@ -142,8 +142,9 @@ function gutenberg_render_elements_support_styles( $pre_render, $block ) { 'skip' => $skip_button_color_serialization, ), 'link' => array( - 'selector' => ".$class_name a:not(.wp-element-button)", - 'hover_selector' => ".$class_name a:not(.wp-element-button):hover", + // :where(:not) matches theme.json selector. + 'selector' => ".$class_name a:where(:not(.wp-element-button))", + 'hover_selector' => ".$class_name a:where(:not(.wp-element-button)):hover", 'skip' => $skip_link_color_serialization, ), 'heading' => array( diff --git a/phpunit/block-supports/elements-test.php b/phpunit/block-supports/elements-test.php index 54411728e95cb..a25a5a8b3d785 100644 --- a/phpunit/block-supports/elements-test.php +++ b/phpunit/block-supports/elements-test.php @@ -273,8 +273,8 @@ public function data_elements_block_support_styles() { ), ), ), - 'expected_styles' => '/^.wp-elements-[a-f0-9]{32} a:not\(.wp-element-button\)' . $color_css_rules . - '.wp-elements-[a-f0-9]{32} a:not\(.wp-element-button\):hover' . $color_css_rules . '$/', + 'expected_styles' => '/^.wp-elements-[a-f0-9]{32} a:where\(:not\(.wp-element-button\)\)' . $color_css_rules . + '.wp-elements-[a-f0-9]{32} a:where\(:not\(.wp-element-button\)\):hover' . $color_css_rules . '$/', ), 'generic heading element styles are applied' => array( 'color_settings' => array( 'heading' => true ),