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

Color Panel appears on group block even if disabled in theme.json #41293

Closed
johnstonphilip opened this issue May 25, 2022 · 11 comments
Closed

Color Panel appears on group block even if disabled in theme.json #41293

johnstonphilip opened this issue May 25, 2022 · 11 comments
Labels
[Feature] Colors Color management [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Bug An existing feature does not function as intended

Comments

@johnstonphilip
Copy link
Contributor

Description

If I disable everything relating to colors in theme.json, the panel still shows up on blocks that support it, such the group block.

Step-by-step reproduction instructions

  1. In a block theme, set theme.json like this:
{
    "version": 2,
    "settings": {
        "color": {
            "custom": false,
            "customDuotone": false,
            "customGradient": false,
            "defaultGradients": false,
            "defaultPalette": false,
            "background": false,
            "defaultDuotone": false,
            "text": false
        }
    }
}
  1. In the block editor, ad a group block. Notice you'll still see a Color panel in the sidebar, even though you can't do anything with it. Interestingly it shows a "background" option that opens a popover with nothing inside it.

Screen Shot 2022-05-24 at 9 11 15 PM

Screenshots, screen recording, code snippet

No response

Environment info

  • Gutenberg 13.3.0-rc.1

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@johnstonphilip johnstonphilip added [Type] Bug An existing feature does not function as intended [Feature] Colors Color management and removed [Feature] Colors Color management labels May 25, 2022
@delawski
Copy link
Contributor

delawski commented Jun 2, 2022

@johnstonphilip Thanks for filing an issue.

While reviewing your ticket, I learned that in order to disable the color panel for a given block, you need to disable color-related properties in the theme.json on a per-block basis.

I.e. setting settings.color. … properties to false globally is insufficient. You need to specifically disable them for every block, like:

{
	"version": 2,
	"settings": {
		"appearanceTools": true,
		"blocks": {
			"core/paragraph": {
				"color": {
					"link": false
				}
			}
		}
	}
}

@johnstonphilip
Copy link
Contributor Author

Interesting. Despite that this is a bug though right? It should never be in this state where it shows but there's no controls within it, unless I'm missing something!

@skorasaurus skorasaurus added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label Jun 7, 2022
@MatzeKitt
Copy link
Contributor

By the way, it’s the same if you don’t use a theme.json (so if you’re not using a block-based theme) and disable it via add_theme_support( 'disable-custom-colors' );.

@ALJ
Copy link

ALJ commented Jun 9, 2022

@johnstonphilip I experimented with the color object from your theme.json and just one inclusion successfully hid that broken Color panel. Try this; notice the inclusion of "gradients": []:

"color": {
  "custom": false,
  "customDuotone": false,
  "customGradient": false,
  "defaultGradients": false,
  "defaultPalette": false,
  "background": false,
  "defaultDuotone": false,
  "text": false,
  "gradients": []
},

Having said that, I've come across a very similar bug (I assume it's a bug). The core/button block's Border panel still displays even when disabling borders globally with:

{
  "version": 2,
  "settings": {
    "appearanceTools": false,
    "border": {
      "color": false,
      "radius": false,
      "style": false,
      "width": false
    },
  },
}

Even with the above, I have to add the same radius: false on core/button later in the same theme.json file in order to hide the panel.

@MatzeKitt
Copy link
Contributor

MatzeKitt commented Jun 10, 2022

This seems to be because there is a check beforehand if __experimentalBorder is supported:

const support = getBlockSupport( blockName, BORDER_SUPPORT_KEY );
if ( support === true ) {
return true;
}

However, you can disable it specifically for the button block:

https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-json/#settings-examples

@ALJ
Copy link

ALJ commented Jun 10, 2022

Thank you @MatzeKitt for the context and look through the code 😄 ... my point was this behavior is unexpected to me. I expect no block to show Radius in a Border panel when that is specifically set to false in the global theme.json settings.

@MatzeKitt
Copy link
Contributor

I’m absolutely on the same side but just wanted to point out a solution, since I needed it. 😄

@johnstonphilip
Copy link
Contributor Author

johnstonphilip commented Jul 22, 2022

I was able to trace this down to 2 places.

The first place is here:

Really, if there's nothing to show, that should return null instead of the Dropdown component. I wasn't able to find the right way to check what is available to show though.

I wasn't able to track down whether the value of toggleSettings would help to know if there's anything to show.

But while fixing that would at least make the Background button dissapear, you'd then be left with an empty color panel like this:

Screen Shot 2022-07-22 at 4 39 33 PM

I was able to track that down to here:

<InspectorControls __experimentalGroup="color">

This would be the more ideal place to do a should we show anything here? before rendering a blank Color Panel.

Unfortunately I ran out of time to pursue this further today.

@tellthemachines
Copy link
Contributor

Looking into this behaviour a bit, it seems that both on a global and a block level, it's possible to disable text and link colors individually, but for background to disappear altogether we need at least

"color": {
  "background": false,
  "gradients": [],
  "customGradient": false
}

(Also, setting gradient to false triggers a PHP warning, which is unexpected.)

For the color panel to not render for a specific block type, it's enough to disable all the color settings for that block, e.g., for Gallery, that has only background, the above code snippet is enough to make the panel go away.

In my testing, the following global setting was enough to hide the color controls altogether for all blocks:

"color": {
	"link": false,
  	"text": false,
  	"background": false,
  	"gradients": [],
	"customGradient": false
}

While this works, it's not at all intuitive and could use some improvement.

It should be possible to remove the "background" control by just setting "background': false. Likewise, ideally it should be possible to disable the whole color panel by setting "color": false, rather than being forced to disable each individual setting within color.

@tellthemachines tellthemachines added [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Feature] Colors Color management labels Oct 21, 2022
SteveRyan-ASU added a commit to asuengineering/pitchfork that referenced this issue Feb 27, 2023
Source: WordPress/gutenberg#41293 (comment)

Needed to set `gradient: []` in theme.json to prevent that box from showing up if other bg colors not supported.
@carolinan
Copy link
Contributor

I am not able to reproduce this issue anymore in 6.4.3 and 6.5 RC.
The following disables the color panel for me:

		"color": {
			"text": false,
			"background": false,
			"link": false,
			"custom": false,
			"customDuotone": false,
			"customGradient": false,
			"defaultDuotone": false,
			"defaultGradients": false,
			"defaultPalette": false
		}

@MatzeKitt
Copy link
Contributor

Can confirm that the settings are now being respected correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Colors Color management [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

7 participants