-
Notifications
You must be signed in to change notification settings - Fork 2.1k
mdc-theme CSS variable customization for calculated colors #4431
Comments
I've already partly referenced this issue in #4256, but when I've tried to change theme colors globally via css vars, it seems that the problem affects many components. |
Thanks for filing this issue! 😀 In order to meet accessibility requirements for contrast ratios, we frequently need to calculate the lightness/darkness level of a color. It's not possible to do this in pure CSS, so we do it in Sass mixins and functions instead. The material-components-web/packages/mdc-theme/_mixins.scss Lines 104 to 113 in 70672f1
Unfortunately, we don't do the same thing for calculated colors, which leaves CSS-only users hanging. If you're looking for runtime theme customization, your best option is to compile two separate stylesheets with Sass, and switch between them. Our old Demo pages do this (clone the repo and run material-components-web/demos/theme/index.js Lines 180 to 185 in 70672f1
material-components-web/demos/interactivity.js Lines 192 to 216 in 70672f1
We'd love to fix this at some point, but it's unlikely we'll have the resources to address it in the foreseeable future 😢 |
Notable suggestions for solving this: There is also likely to be more work on the color system this year which may also impact this in some way. |
Closing this as dup of #4709 |
Hi!
I am trying to implement switching between light and dark themes in my app.
As far as I understand, to switch between two themes at runtime, without sass recompilation, I should override some css variables. I've declared a CSS class applied to the
:root
element where the variables like--mdc-theme-primary
,--mdc-theme-background
and others are redefined.Despite the seeming simplicity of the described approach, I am facing some issues. Here is a couple of them:
1. MDCDrawer SASS mixins for styling inner lists are defined in the following manner:
Inside this mixin, another MDCTheme mixin,
mdc-theme-prop-value
, is used. It means that the color of list item text is not controlled by CSS variables, hence not customizable.2. MDCTopAppBar SASS mixins for customizing fill color are defined as follows:
Inside this mixin, another MDCTheme mixin,
mdc-theme-accessible-ink-color
, is used.It is defined as follows:
Once again, the
mdc-them-prop-value
mixin is used inside, and this breaks ink color customization by CSS variables.How can I fix the mentioned issues? Maybe my approach for theme switching is wrong?
Or the color system of material components web is not yet finished/debugged?
The text was updated successfully, but these errors were encountered: