-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix: State styles – clear background-image when hover sets a solid background-color
#12182
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
Closed
+125
−1
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
997cf67
Fix: clear background-image when state sets solid background-color
i-am-chitti e55517b
Tests: add tests for clearing background-image state
i-am-chitti 5f175f2
Tests: fix unit tests
i-am-chitti 18032ca
Merge branch 'trunk' into 65239-state-styles-fix
i-am-chitti 9110b32
Chore: update function doc
i-am-chitti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,6 +136,93 @@ public function test_preserves_authored_border_style_declarations() { | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that background-image reset is added when a state sets a solid background-color. | ||
| * | ||
| * @covers ::wp_get_state_declarations_with_background_resets | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new tests should have
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||
| * | ||
| * @ticket 65239 | ||
| */ | ||
| public function test_adds_background_image_reset_for_solid_background_color() { | ||
| $actual = wp_get_state_declarations_with_background_resets( | ||
| array( | ||
| 'background-color' => '#ff0000 !important', | ||
| ) | ||
| ); | ||
|
|
||
| $this->assertSame( | ||
| array( | ||
| 'background-color' => '#ff0000 !important', | ||
| 'background-image' => 'unset !important', | ||
| ), | ||
| $actual | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that background-image reset is not added when the state also sets a legacy gradient. | ||
| * | ||
| * @covers ::wp_get_state_declarations_with_background_resets | ||
| * | ||
| * @ticket 65239 | ||
| */ | ||
| public function test_no_background_image_reset_when_state_sets_legacy_gradient() { | ||
| $actual = wp_get_state_declarations_with_background_resets( | ||
| array( | ||
| 'background-color' => '#ff0000 !important', | ||
| 'background' => 'linear-gradient(135deg, #ff0000, #0000ff) !important', | ||
| ) | ||
| ); | ||
|
|
||
| $this->assertSame( | ||
| array( | ||
| 'background-color' => '#ff0000 !important', | ||
| 'background' => 'linear-gradient(135deg, #ff0000, #0000ff) !important', | ||
| ), | ||
| $actual | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that background-image reset is not added when the state also sets a modern gradient. | ||
| * | ||
| * @covers ::wp_get_state_declarations_with_background_resets | ||
| * | ||
| * @ticket 65239 | ||
| */ | ||
| public function test_no_background_image_reset_when_state_sets_modern_gradient() { | ||
| $actual = wp_get_state_declarations_with_background_resets( | ||
| array( | ||
| 'background-color' => '#ff0000 !important', | ||
| 'background-image' => 'linear-gradient(135deg, #ff0000, #0000ff) !important', | ||
| ) | ||
| ); | ||
|
|
||
| $this->assertSame( | ||
| array( | ||
| 'background-color' => '#ff0000 !important', | ||
| 'background-image' => 'linear-gradient(135deg, #ff0000, #0000ff) !important', | ||
| ), | ||
| $actual | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that declarations without background-color are returned unchanged. | ||
| * | ||
| * @covers ::wp_get_state_declarations_with_background_resets | ||
| * | ||
| * @ticket 65239 | ||
| */ | ||
| public function test_no_background_reset_when_no_background_color() { | ||
| $input = array( | ||
| 'color' => '#ff0000 !important', | ||
| ); | ||
| $actual = wp_get_state_declarations_with_background_resets( $input ); | ||
|
|
||
| $this->assertSame( $input, $actual ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that modifier classes on the first compound selector are preserved | ||
| * when state selectors are scoped to the block wrapper. | ||
|
|
@@ -835,7 +922,7 @@ public function test_responsive_pseudo_state_generates_media_query_scoped_css() | |
| $actual_stylesheet = wp_style_engine_get_stylesheet_from_context( 'block-supports', array( 'prettify' => false ) ); | ||
|
|
||
| $this->assertStringContainsString( | ||
| '@media (width <= 480px){.' . $matches[0] . ' .wp-block-button__link:hover{background-color:#ff00d0 !important;}}', | ||
| '@media (width <= 480px){.' . $matches[0] . ' .wp-block-button__link:hover{background-color:#ff00d0 !important;background-image:unset !important;}}', | ||
| $actual_stylesheet | ||
| ); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function needs an
@since 7.1.0tag here (see other functions in this file for comparison).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed