You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And there exists some Sass mixin to customize the color of mdc-bar
@mixinmdc-bar-color($color) {
color: $color;
}
Now lets say that the mdc-foo component wants to have a blue mdc-bar in the default state, but a red mdc-bar in the invalid state. Then the stylesheet for mdc-foo has
(Also disclaimer it could use a bit of cleanup, probably)
This tries to pretty exhaustively replace .mdc-bar with .mdc-bar__sub otherwise append it to the selector, but I can already identify a couple of problems:
We wouldn't want this behavior when we're using it in the context of purely .mdc-bar (this is probably detectable at least in the simplest case of the selector only being that)
It doesn't detect its use within compound selectors e.g. .my-modifier.mdc-bar which IIUC ideally would also remove just the .mdc-bar. I don't think this is even possible to do within Sass without risking false positives (e.g. looking for .mdc-bar but ending up matching .mdc-bark and replacing all but the last letter).
It also occurs to me that maybe this is something we should seek to solve via documentation rather than implementing safeguards to attempt to tweak parent selectors, which seems likely to be error-prone.
I've already wondered this after seeing how some of our components' mixins include a selector vs. how some don't (e.g. look at how mdc-toolbar-icon-ink-color works vs. mdc-tab-icon-ink-color)...
Do you think it's viable to include some indication in our mixin documentation tables as to whether the mixin includes a sub-element selector, and write some centralized guidance somewhere on what that means for using it within custom selectors?
Take this made up example of the
mdc-foo
component using themdc-bar
component in its internal implementation:And there exists some Sass mixin to customize the color of mdc-bar
Now lets say that the
mdc-foo
component wants to have a bluemdc-bar
in the default state, but a redmdc-bar
in the invalid state. Then the stylesheet formdc-foo
haswhich outputs this CSS, once Sass is compiled.
...so far so good...
The problem is if we change the implementation of
mdc-bar
so that it has a sub-elementAnd we have to update the implementation of the Sass mixin
mdc-bar-color
All these changes happen in the
mdc-bar
node module, and none of them are breaking changes...but now themdc-foo
stylesheet outputswhich is unnecessarily specific
How do we handle this case more gracefully?
The text was updated successfully, but these errors were encountered: