diff --git a/packages/block-editor/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js b/packages/block-editor/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js
index 8ed039565ae47..917ca04783de1 100644
--- a/packages/block-editor/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js
+++ b/packages/block-editor/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js
@@ -61,7 +61,12 @@ export default function useMultipleOriginColorsAndGradients() {
} );
}
return result;
- }, [ defaultColors, themeColors, customColors ] );
+ }, [
+ defaultColors,
+ themeColors,
+ customColors,
+ shouldDisplayDefaultColors,
+ ] );
const customGradients = useSetting( 'color.gradients.custom' );
const themeGradients = useSetting( 'color.gradients.theme' );
@@ -103,7 +108,16 @@ export default function useMultipleOriginColorsAndGradients() {
} );
}
return result;
- }, [ customGradients, themeGradients, defaultGradients ] );
+ }, [
+ customGradients,
+ themeGradients,
+ defaultGradients,
+ shouldDisplayDefaultGradients,
+ ] );
+
+ colorGradientSettings.hasColorsOrGradients =
+ !! colorGradientSettings.colors.length ||
+ !! colorGradientSettings.gradients.length;
return colorGradientSettings;
}
diff --git a/packages/block-library/src/cover/edit/inspector-controls.js b/packages/block-library/src/cover/edit/inspector-controls.js
index f99180d7601fd..d5a692350993f 100644
--- a/packages/block-library/src/cover/edit/inspector-controls.js
+++ b/packages/block-library/src/cover/edit/inspector-controls.js
@@ -249,62 +249,64 @@ export default function CoverInspectorControls( {
) }
-
- ( {
- overlayColor: undefined,
- customOverlayColor: undefined,
- gradient: undefined,
- customGradient: undefined,
- } ),
- },
- ] }
- panelId={ clientId }
- { ...colorGradientSettings }
- />
- {
- // If there's a media background the dimRatio will be
- // defaulted to 50 whereas it will be 100 for colors.
- return dimRatio === undefined
- ? false
- : dimRatio !== ( url ? 50 : 100 );
- } }
- label={ __( 'Overlay opacity' ) }
- onDeselect={ () =>
- setAttributes( { dimRatio: url ? 50 : 100 } )
- }
- resetAllFilter={ () => ( {
- dimRatio: url ? 50 : 100,
- } ) }
- isShownByDefault
- panelId={ clientId }
- >
-
+ ( {
+ overlayColor: undefined,
+ customOverlayColor: undefined,
+ gradient: undefined,
+ customGradient: undefined,
+ } ),
+ },
+ ] }
+ panelId={ clientId }
+ { ...colorGradientSettings }
+ />
+ {
+ // If there's a media background the dimRatio will be
+ // defaulted to 50 whereas it will be 100 for colors.
+ return dimRatio === undefined
+ ? false
+ : dimRatio !== ( url ? 50 : 100 );
+ } }
label={ __( 'Overlay opacity' ) }
- value={ dimRatio }
- onChange={ ( newDimRation ) =>
- setAttributes( {
- dimRatio: newDimRation,
- } )
+ onDeselect={ () =>
+ setAttributes( { dimRatio: url ? 50 : 100 } )
}
- min={ 0 }
- max={ 100 }
- step={ 10 }
- required
- />
-
-
+ resetAllFilter={ () => ( {
+ dimRatio: url ? 50 : 100,
+ } ) }
+ isShownByDefault
+ panelId={ clientId }
+ >
+
+ setAttributes( {
+ dimRatio: newDimRation,
+ } )
+ }
+ min={ 0 }
+ max={ 100 }
+ step={ 10 }
+ required
+ />
+
+
+ ) }
!! minHeight }
diff --git a/packages/block-library/src/cover/test/edit.js b/packages/block-library/src/cover/test/edit.js
index 09acd674c6af3..e399f379e2155 100644
--- a/packages/block-library/src/cover/test/edit.js
+++ b/packages/block-library/src/cover/test/edit.js
@@ -12,9 +12,34 @@ import {
selectBlock,
} from 'test/integration/helpers/integration-test-editor';
-async function setup( attributes ) {
+const defaultSettings = {
+ __experimentalFeatures: {
+ color: {
+ defaultPalette: true,
+ defaultGradients: true,
+ palette: {
+ default: [ { name: 'Black', slug: 'black', color: '#000000' } ],
+ },
+ },
+ },
+ colors: [ { name: 'Black', slug: 'black', color: '#000000' } ],
+ disableCustomColors: false,
+ disableCustomGradients: false,
+};
+
+const disabledColorSettings = {
+ color: {
+ defaultPalette: false,
+ defaultGradients: false,
+ },
+ disableCustomColors: true,
+ disableCustomGradients: true,
+};
+
+async function setup( attributes, useCoreBlocks, customSettings ) {
const testBlock = { name: 'core/cover', attributes };
- return initializeEditor( testBlock );
+ const settings = customSettings || defaultSettings;
+ return initializeEditor( testBlock, useCoreBlocks, settings );
}
async function createAndSelectBlock() {
@@ -296,6 +321,35 @@ describe( 'Cover block', () => {
expect( overlay[ 0 ] ).toHaveClass( 'has-background-dim-30' );
} );
+
+ describe( 'when colors are disabled', () => {
+ test( 'does not render overlay control', async () => {
+ await setup( undefined, true, disabledColorSettings );
+ await createAndSelectBlock();
+ await userEvent.click(
+ screen.getByRole( 'tab', { name: 'Styles' } )
+ );
+
+ const overlayControl = screen.queryByRole( 'button', {
+ name: 'Overlay',
+ } );
+
+ expect( overlayControl ).not.toBeInTheDocument();
+ } );
+ test( 'does not render opacity control', async () => {
+ await setup( undefined, true, disabledColorSettings );
+ await createAndSelectBlock();
+ await userEvent.click(
+ screen.getByRole( 'tab', { name: 'Styles' } )
+ );
+
+ const opacityControl = screen.queryByRole( 'slider', {
+ name: 'Overlay opacity',
+ } );
+
+ expect( opacityControl ).not.toBeInTheDocument();
+ } );
+ } );
} );
describe( 'Dimensions panel', () => {