question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add !default to more scss variables to allow overriding values

See original GitHub issue

Bug, feature request, or proposal:

Feature Request

What is the expected behavior?

Custom theme should be able to override most colors/styles used in material theme (assuming they are SCSS variables). This override should be possible at time of theme generation and not by overriding CSS after the fact. The variables are already there but some are marked as !default while others (that could also be) are not.

What is the current behavior?

Certain variables ($light-primary-text, entire $mat-grey palette) are used directly in SCSS and not via theme setup ($mat-light-theme-foreground). These should have !default flag to allow customization at theme generation time.

What is the use-case or motivation for changing an existing behavior?

To cleanly override some of these colors, I currently make a copy of _theming.scss and update this file manually so I don’t have to override CSS after it has been generated; thus maintain brittle CSS that might change in future material updates.

Is there anything else we should know?

This suggestion simply implies adding !default to a few more variables, I realize current behavior is likely deliberate to prevent users from shooting themselves in the foot, but this also has a side effect; if someone is going to override these variables it’s on them, no different than rest of styling.

There seems to be a slight syntax variant in how to override maps that’s different than standard variables i.e.

$grays: () !default; $grays: map-merge(( "100": $gray-100, "200": $gray-200, "300": $gray-300, etc... ), $grays);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
tomgruszowskicommented, Nov 27, 2018

Thanks for linking to these issues @jelbourn but there is clearly a desire for this from the community, it seems too easily dismissed, especially since level of effort here appears reasonable (unless I’m missing something). We’re already compiling downstream when theming with SCSS what harm can there be from exposing the variables? CSS variables are not some magic bullet, SCSS variables will make sense for years to come. It’s disappointing that the material team takes such a restricted stance on styling while being extremely strong on the component architecture. Again, apologies if I don’t understand the details well enough, but it doesn’t strike me as anyone is trying to solve this.

3reactions
jelbourncommented, Nov 27, 2018

The fundamental issue here is twofold.

Issue number one is that making this possible would make the Sass surface a public API. The existing public API surface area for Angular CDK + Material is already huge; the more we open this up, the harder it becomes to make any changes at all.

Issue number two is the build graph. Any given component uses styleUrls to reference a CSS file. When we publish the library, that CSS file has to exist, so the compilation has to happen before publishing. Angular doesn’t have a way to hot-swap style files that would enable leaf applications to affect the CSS that’s associated with the component.

CSS variables really do make this problem much easier to address. Because we’re so close to using them, it’s ultimately going to be the most effective use of the team’s time to revisit the theming system just once.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A story about overriding SASS variables and the '!default ...
This article describes how to use the !default keyword in SCSS when overriding variables. It will also save you a few hours of...
Read more >
How to overwrite SCSS variables when compiling to CSS
I've tried it with more variables and different file imports, but the result is always, that my override values are not incorporated. The...
Read more >
Variables - Sass
The configured values will override the variables' default values. Only variables written at the top level of the stylesheet with a !default flag...
Read more >
A Sass `!default` use case - Thoughtbot
So using Sass !default is like adding an “unless this is already ... Normally to override variables, you have to define the new...
Read more >
Overriding SCSS variables | JavaScript - EJ 2 Forums
We can override the SCSS variables after referring its definition file to achieve your requirement instead of adding !default flag to each ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found