material-components-web icon indicating copy to clipboard operation
material-components-web copied to clipboard

On Primary Secondary text colours on Primary background

Open RhysyG opened this issue 8 years ago • 5 comments

I want to be able to theme secondary text on primary background.

What MDC Web Version are you using?

@material/theme@^0.35.0

What browser(s) is this bug affecting?

Chrome

What OS are you using?

High Seirra

What are the steps to reproduce the bug?

Create a Parent div with @include mdc-theme-prop(background-color, primary);

Create child div with: @include mdc-theme-prop(color, on-primary);

What is the desired behavior?

To be able to theme secondary text on primary background. Note: And not just text, but inputs too.

What is the actual behavior?

Only having an option to have primary text on primary background.

primary-secondary

RhysyG avatar Jul 20 '18 03:07 RhysyG

Can you please share your code where you're using secondary text?

You might want to try this:

.demo-primary-background {
  @include mdc-theme-prop("background-color", primary);
}

.demo-on-primary-text {
  @include mdc-theme-prop("color", text-secondary-on-dark);
}

abhiomkar avatar Jul 20 '18 14:07 abhiomkar

Hi @abhiomkar ,

Yeah that's the thing, there is nothing to support secondary text on primary so I don't have any code to show you.

If I use the below code, it doesn't take into account if my primary color is a very faint blue. When you use the theme-prop on-primary, it detects if the foreground should be dark or light based on the contrast algorithm.

.demo-on-secondary-text {
  @include mdc-theme-prop("color", text-secondary-on-dark); // won't work if primary blue is faint
}

It's like the below statement from the docs https://github.com/material-components/material-components-web/blob/master/docs/theming.md

Ideally, we want a solution which is as maintainable as the mdc-theme--primary-bg class, and which takes into account the primary color, in order to determine whether to overlay white or black text on top.

RhysyG avatar Jul 20 '18 23:07 RhysyG

You could try this SASS function which automatically determines the appropriate color based on contrast tone.

color: mdc-theme-accessible-ink-color(primary, $text-style: secondary);

Whereas, primary is the background color and secondary is the text-style. Hope this helps.

abhiomkar avatar Jul 24 '18 15:07 abhiomkar

Closing this issue because we haven't heard back in a few days.

Feel free to reopen if you're still having trouble 😀

acdvorak avatar Jul 30 '18 21:07 acdvorak

@abhiomkar ,

Thanks, that works a treat. It would be nice if it eventually looked as neat as this markup and utilised the theme-prop to create a css variable.

@include mdc-theme-prop("color", text-secondary-on-primary);

But maybe it's to opinionated for a base set of styles. What do you think? Should I put this forward for an enhancement?

Cheers.

RhysyG avatar Jul 31 '18 00:07 RhysyG