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

ColorPalette: Labels do not change when CSS variables are used #41157

Closed
t-hamano opened this issue May 19, 2022 · 0 comments · Fixed by #41461
Closed

ColorPalette: Labels do not change when CSS variables are used #41157

t-hamano opened this issue May 19, 2022 · 0 comments · Fixed by #41461
Assignees
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended

Comments

@t-hamano
Copy link
Contributor

t-hamano commented May 19, 2022

Description

Related: #39386

In #39386, name and color are now displayed on the palette when a color is selected from the color palette.
It works correctly when the color has a HEX value, but the label is not rendered correctly when the color has a CSS variable.

I would expect that the label is probably not updated correctly at this point:

const buttonLabelName = useMemo(
() =>
extractColorNameFromCurrentValue(
value,
colors,
showMultiplePalettes
),
[ value, colors, showMultiplePalettes ]
);

Step-by-step reproduction instructions

On Block Theme

Define theme.json as follows:

See Code
{
	"version": 2,
	"settings": {
		"color": {
			"palette": [
				{
					"slug": "red",
					"color": "var(--wp--custom--color--r)",
					"name": "Red"
				},
				{
					"slug": "green",
					"color": "var(--wp--custom--color--g)",
					"name": "Green"
				},
				{
					"slug": "blue",
					"color": "var(--wp--custom--color--b)",
					"name": "Blue"
				}
			]
		},
		"custom": {
			"color": {
				"r": "red",
				"g": "green",
				"b": "blue"
			}
		}
	}
}

On Classic Theme

Define functions.php as follows:

See Code
<?php
add_action(
	'after_setup_theme',
	function() {
		add_theme_support(
			'editor-color-palette',
			array(
				array(
					'name'  => 'Red',
					'slug'  => 'red',
					'color' => 'var(--color-red)',
				),
				array(
					'name'  => 'green',
					'slug'  => 'green',
					'color' => 'var(--color-green)',
				),
				array(
					'name'  => 'blue',
					'slug'  => 'blue',
					'color' => 'var(--color-blue)',
				),
			)
		);
	}
);

function custom_enqueue_scripts() {
	wp_enqueue_style( 'custom-style', get_template_directory_uri() . '/style.css'	);
	wp_add_inline_style(
		'custom-style',
		":root {
			--color-red: red;
			--color-green: green;
			--color-blue: blue;
		}"
	);
}
add_action( 'enqueue_block_editor_assets', 'custom_enqueue_scripts' );

Screenshots, screen recording, code snippet

On Block Theme

block-theme.mp4

On Classic Theme

classic-theme.mp4

Environment info

No response

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

@t-hamano t-hamano added the [Package] Components /packages/components label May 19, 2022
@mirka mirka self-assigned this May 31, 2022
@mirka mirka changed the title ColoPallete: Labels do not change when CSS variables are used ColorPalette: Labels do not change when CSS variables are used May 31, 2022
@mirka mirka added the [Type] Bug An existing feature does not function as intended label May 31, 2022
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label May 31, 2022
@priethor priethor removed the [Status] In Progress Tracking issues with work in progress label May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants