Skip to content

Conversation

Rishit30G
Copy link
Contributor

What?

Closes #69980

Why?

This PR is necessary to improve the behaviour of the default duotone unset button

How?

This PR targets the class which sets the blue color to the unset button and sets the color to transparent
It also adds the condition of value === undefined to isUnset to get the checked icon on the unset button

Testing Instructions

  • Create a new post
  • Add an Image Block or any block that has 'Duotone' present
  • Open the Duotone from the right panel ( Styles > Filters > Duotone )
  • Notice that now when we select a duotone option we get a checkmark and on hovering or selecting there is no blue color

Screenshots or screencast

Screen.Recording.2025-04-24.at.3.14.04.PM.mov

@Rishit30G Rishit30G requested a review from ajitbohra as a code owner April 24, 2025 10:12
Copy link

github-actions bot commented Apr 24, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Rishit30G <rishit30g@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka Mamaduka added the [Type] Enhancement A suggestion for improvement. label Apr 25, 2025
@@ -76,7 +76,7 @@ function DuotonePicker( {
[ colorPalette ]
);

const isUnset = value === 'unset';
const isUnset = value === 'unset' || value === undefined;
Copy link
Member

Choose a reason for hiding this comment

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

I'm unsure about this change. The "Unset" is similar to the clear button; I don't think it should be selected when no Duotone value is set.

Copy link
Contributor Author

@Rishit30G Rishit30G Apr 26, 2025

Choose a reason for hiding this comment

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

Makes sense, but the current implementation is also not working, that's the reason why I have introduced undefined
Apart from undefined nothing seems to be working here to get the check option for unset button

Copy link
Member

Choose a reason for hiding this comment

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

It then seems we're trying to solve the wrong problem in the wrong place. Why?

  • The unset is a valid filter and can remove the globally set Duotone filter. It shouldn't be treated as undefined.
  • When this filter is selected, selection should be visible, and it should also be clearable.

The following changes fix these issues in my tests:

diff --git packages/block-editor/src/hooks/duotone.js packages/block-editor/src/hooks/duotone.js
index 246e4fde7d8..b6a1989870d 100644
--- packages/block-editor/src/hooks/duotone.js
+++ packages/block-editor/src/hooks/duotone.js
@@ -124,9 +124,10 @@ function DuotonePanelPure( { style, setAttributes, name } ) {
 		return null;
 	}
 
-	const duotonePresetOrColors = ! Array.isArray( duotoneStyle )
-		? getColorsFromDuotonePreset( duotoneStyle, duotonePalette )
-		: duotoneStyle;
+	const duotonePresetOrColors =
+		duotoneStyle === 'unset' || Array.isArray( duotoneStyle )
+			? duotoneStyle
+			: getColorsFromDuotonePreset( duotoneStyle, duotonePalette );
 
 	return (
 		<>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It then seems we're trying to solve the wrong problem in the wrong place. Why?

My apologies, I wasn't aware of this file, I was trying to fix the component itself 🙇🏻

When this filter is selected, selection should be visible, and it should also be clearable.

Yes, I have updated the file with the shared diff, thanks!

@t-hamano t-hamano added the [Package] Components /packages/components label Apr 28, 2025
@Rishit30G Rishit30G requested a review from tellthemachines as a code owner May 2, 2025 01:47
@Rishit30G Rishit30G requested a review from Mamaduka May 2, 2025 01:48
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

The fix works as expected. Thanks, @Rishit30G!

@Rishit30G
Copy link
Contributor Author

Thanks @Mamaduka for approving the PR, if we are all set then we consider merging this! 💯

@Mamaduka Mamaduka merged commit 46d8ddb into WordPress:trunk May 2, 2025
63 of 64 checks passed
@github-actions github-actions bot added this to the Gutenberg 20.8 milestone May 2, 2025
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
Co-authored-by: Rishit30G <rishit30g@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duotone: Improve the unset button
3 participants