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

Elements: Fix instance element styles for links applying to buttons #6127

Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/wp-includes/block-supports/elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ function wp_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:where(:not(.wp-element-button))",
'hover_selector' => ".$class_name a:where(:not(.wp-element-button)):hover",
Comment on lines +169 to +170
Copy link
Member

@mukeshpanchal27 mukeshpanchal27 Feb 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a:not(.wp-element-button)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the question @mukeshpanchal27, I take it you mean "why not use :not"?

This selector uses the :where to reduce specificity and make it easier for themes to override the link element styles as desired.

In the case of this PR, it's a bug fix that prevents the misapplication of the link element styles to buttons but by using the same selector as theme.json it also avoids increasing the specificity. This keeps the ease of overriding styles if a theme desires while still resulting in the expected behaviour.

The original PR introducing the lowered specificity for link element styles in theme.json can be found in WordPress/gutenberg#42669. That was backported in #3206.

'skip' => $skip_link_color_serialization,
),
'heading' => array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function tear_down() {
* Tests that elements block support generates appropriate styles.
*
* @ticket 59555
* @ticket 60557
*
* @covers ::wp_render_elements_support_styles
*
Expand Down Expand Up @@ -139,8 +140,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: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 ),
Expand Down
Loading