-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Improved parent selector support for :host ? #3126
Comments
Well, on one hand I can guess how tempting it may seem to just "fix" the compiler to do "the right thing". On the other hand this is clearly would be the same "guess the user intentions" stuff as in #1942, #1605 etc. (Generally rejected because we'll end up with lotsa exceptional non-maintainable spagetti stacks instead of strict and straight-forward selector rendering rules. Or in other words: normally we should try to not break the "identical code should produce identical result" rule or it will break us in return). Notice that the example is basically the same as:: :not {
.shared-style; // same wrong result
} etc. And for a big picture all this can be reduced to the completely artificial and ridiculous:
-> dybo {color: red} /* uhmm, shouldn't this be body instead? */ So I'd rather said this (fairly reasonable, as well as issues mentioned above) use-case needs some fundamentally different idea/design-pattern. |
I agree that the compiler should not just be the answer to fixing it. You would use // Like you said, it's the same issue as :host, however, this is very confused selector
// and is unlikely the share styles as they return very different elements.
// If they did share styles, they are likely to be minimal with simple selectors.
button, :not {
&[attr] {
color: red;
}
}
// Also looks unlikely, but imagine the :host is compiled separately in another file.
// Both elements are buttons, for example, so they can share a large amount of styles.
button, :host {
&[attr] {
color: red;
}
} Currently we are wrapping |
Observation .shared-style() {
&:hover {
color: red;
}
}
button {.shared-style}
host_ {.shared-style}
// adapter:
:host(:extend(host_ all)) {}
// ^ fail: currently `extend` does not work in parens |
True, although Currently we compile custom element styles individually to separate out the multiple Maybe this is quite niche as we're styling native and custom elements together... |
Then I'm giving up (there's no fun in trying to find a consistent pattern for such inconsistent overengineered system like this |
Haha, fair enough. Custom elements are a bit of a pain. Cheers anyway. |
You're closing to early I think. I'd wait for other opinions (me is known to be against everything and whining the most). After all there may be some neat idea flying around that could make everybody happy :)... (After all such sketching for possible workarounds sometimes makes one to step into weird never-seen-yet snippets like this for example) |
You rang? ;-) Sounds like what @TremayneChrist is asking for here is something akin to the Maybe work off of a combination of both, e.g. with a :host(!&) {
.shared-style;
} This type of feature could generally be quite useful, imho. I know that in the past I've run into my fair share of prickly situations where I was stuck muttering curses while refactoring large parts of complicated mixin-based components, that ended up with a neeed to insert child selectors 'into the middle' of a parent selector. And ofcourse; Less doesn't support that. Not at all different from the |
Curiously just yesterday I thought of something similar as an alternative for #1075 (which, in either of its forms, solves too narrow problem set and has too many problems fixing the others). div:hook(foo) span:not(:hook(bar, #boo)) {
:set-hook(foo, :hover) {1:1}
p:set-hook(foo, ::before):set-hook(bar, .btn) {2:2}
} -> css: div:hover span:not(#boo) {1:1}
div::before span:not(.btn) p {2:2} (No idea how this can be simplified (all three constraints I mentioned above will make whatever syntax to be very verbose I guess), though the scariness is to be compared against either of #1075 variant limitations). In a simplest case (no name, no fallback value) the placeholder becomes just :host(:hook) {
div {...} // -> :host(div)
} (using div {
!& {...} // -> !div
} |
True. In this cases though, I think you could get away with the reverse order |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
https://developers.google.com/web/fundamentals/web-components/shadowdom#styling
It's hard to understand how to create shared styles for native and custom elements (light vs shadow DOM)
Example:
button.less
my-custom-button.less
../shared/button-styles.less
CSS output
This is incorrect as
:host
requires any other selectors to be placed inside of parentheses.For example:
This can be fixed for
:host
by doing:The problem is that this then breaks the
button
styles which is not ideal when sharing styles between native and custom elements - it all gets a bit complicated.Breaking up the mixin into smaller parts is an option, however, as
:host
always requires parentheses, could {less} automatically output them in the CSS?The text was updated successfully, but these errors were encountered: