From 360af4d8a710baf6d3545de52fe4cff38ecd6e2a Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 24 Feb 2023 09:18:47 +0000 Subject: [PATCH] Handle mutually exclusivity of attributes --- packages/block-editor/src/hooks/duotone.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/hooks/duotone.js b/packages/block-editor/src/hooks/duotone.js index 9e42822c793e3..e9d586201c20f 100644 --- a/packages/block-editor/src/hooks/duotone.js +++ b/packages/block-editor/src/hooks/duotone.js @@ -123,9 +123,15 @@ function DuotonePanel( { attributes, setAttributes } ) { return null; } - const duotonePresetOrColors = duotonePreset - ? getColorsFromDuotonePreset( duotonePreset, duotonePalette ) - : duotoneColors; + let duotonePresetOrColors; + + if ( duotoneColors === 'unset' ) { + duotonePresetOrColors = 'unset'; + } else { + duotonePresetOrColors = duotonePreset + ? getColorsFromDuotonePreset( duotonePreset, duotonePalette ) + : duotoneColors; + } return ( @@ -146,6 +152,13 @@ function DuotonePanel( { attributes, setAttributes } ) { if ( maybePreset ) { // Duotone presets are stored in a separate attribute. newDuotoneAttributes.duotone = maybePreset; + newDuotoneAttributes.style = { + ...style, + color: { + ...style?.color, + duotone: '', // remove any custom colors + }, + }; // Todo: should we store the custom colors **as well** // in the style attribute as a fallback? @@ -158,6 +171,8 @@ function DuotonePanel( { attributes, setAttributes } ) { duotone: newDuotone, // custom colors }, }; + // Remove any presets. + newDuotoneAttributes.duotone = ''; } setAttributes( newDuotoneAttributes );