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

Styles: add gradient support to text color options #49642

Open
annezazu opened this issue Apr 6, 2023 · 3 comments
Open

Styles: add gradient support to text color options #49642

annezazu opened this issue Apr 6, 2023 · 3 comments
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement.

Comments

@annezazu
Copy link
Contributor

annezazu commented Apr 6, 2023

This was mentioned as part of the FSE Outreach Program's Build a Block Theme exploration in this mentioned summary post

Currently there is no way to add colour gradients to the text colour. This has to be done with CSS. This is likely quite difficult to achieve and isn’t the highest priority at the moment, but would be a great feature in the future.

My brain immediately went to some sort of accessibility concerns but wanted to note either way to see what folks thought! To be clear, this is for Site Editor > Styles > Color > Text:

Screen Shot 2023-04-06 at 9 15 12 AM

@annezazu annezazu added [Type] Enhancement A suggestion for improvement. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Apr 6, 2023
@aaronrobertshaw
Copy link
Contributor

As you note, there might be some accessibility concerns with gradients. I imagine it might be tricky to effectively check the text's contrast with its background.

Perhaps we could use a similar approach here as we did when enabling the alpha channel for text colors. In that case, if we didn't otherwise detect a contrast issue and the text was transparent at all, we warn about the potential accessibility issue.

The PR introducing the alpha channel checking can be found here: #38100

@justintadlock
Copy link
Contributor

It's also worth noting that gradient text isn't a supported feature in CSS. Gradients are, for all intents and purposes, images in CSS.

The most common method to "fake" gradient text is to assign a background image, add background-clip to the element, and make the text transparent so that the background shines through.

Here's some sample CSS from a "clip text" Heading block style I have:

.wp-block-heading.is-style-clip-text {
	background-clip: text !important;
	-webkit-background-clip: text !important;
	color: transparent !important;
}

/* Add a default background in case user hasn't selected one. */
.wp-block-heading.is-style-clip-text:not( .has-background ) {
	background: var( --wp--preset--gradient--cool-to-warm-spectrum );
}

/* Make sure sub-element text is also transparent. */
.wp-block-heading.is-style-clip-text > * {
	color: inherit !important;
}

That part is not particularly complex.

Making the UX work well for this would be the toughest part because you'd have to (under the hood) migrate the "text" gradient to the background and also hide the background setting in the UI.

I'm not sure if there are other methods for making text appear as if it had a gradient color.

@insaineyesay
Copy link

After adding
.wp-block-heading.is-style-clip-text {
background-clip: text !important;
-webkit-background-clip: text !important;
color: transparent !important;
}

my gradients worked.
Thanks @justintadlock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

4 participants