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
{{ message }}
Repository navigation
The way Extend works - more complicated selectors and change in matching #1155
I have finally gotten around to testing this and wanted to post my initial findings. I have been using the alpha version less-1.4.0-alpha.js on the client-side only (no command line yet - not that it should be any different really).
So far, everything works as I would expect except for two major drawbacks which can be explained with one example. Take the following code which is located in one of my root LESS files:
Issue 1 - styles defined within media queries do not get extended. Anything trying to extend the .container class only gets the margin: 0 auto styles.
.some-element:extend(.container);
Issue 2 - compound selectors do not get extended. However, the first participant DOES get extended. For example, the following incorrectly extends the .container styles but not the intended .container.positioned styles.
.some-element:extend(.container.positioned);
I wish I could provide a solution. Hope this helps.
I have a request for the moderator so that someone doesn't try and use my code in their projects. It turns out that specifying media queries in rem doesn't work in some browsers (Safari, iPad Chrome, iPad Safari, etc). This was an experimental feature I was testing. Could you please change the values in the media query definitions to em. The .container width and margins can still use rem (and should).
issue 2 is just a missing feature.. surprised it parses as the contents of :extend( should be a single class or node selector. maybe a feature request for the future.
media queries.
if you extend a class that is in a media query it should "just work" - it clearly doesn't and I agree with you
if you do an extend inside a media query shouldn't it copy the code inside the media query? E.g. in your simple example it would act the same as .shared-style; but in more complex examples it would pull in the bits of the selector too
Regarding your point number 1 - I think selector matching isn't a feature but a requirement. Can we not pull parts of sizzle in so that all selector patterns get matched?
Regarding your point 2 about copying the code - I agree, but the problem gets very complicated if you have something like this, as the parser will have to be smart enough to apply styles from other media queries:
-- take note of the single :extend below, then take note of the comments --
/* These styles should be copied */
.shared-style { ... }
@media screen and (min-width: 30em) {
/* These styles should be copied */
.shared-style { ... }
}
@media screen and (max-width: 30em) {
.shared-style { ... }
}
@media screen and (min-width: 48em) {
.some-element:extend(.shared-style) {
/* Copied styles should be pasted here */
}
}
@media screen and (min-width: 60em) {
.shared-style { ... }
}
@media screen and (max-width: 60em) {
/* These styles should be copied */
.shared-style { ... }
}
@DesignByOnyx, I'm going to have to spend more time with your use case, but honestly after using SASS extends and doing a lot of testing on extends myself, I'm not sure I agree with any of your point(s) about number 1 (that's the only part I'm responding to here). The "comprehensive selector matching" was something I personally don't like - and didn't like about SASS. Why would you want to extend to every selector pattern? I really am curious, that's not intended as a statement...
From my standpoint, the Less.js implementation and syntax for extends are far more powerful than SASS and allow you to use a surgical "laser" approach with design practices, rather than using than a shotgun blast. Seems like the "sizzle" is very specifically the ability choose what you want to extend.
However, I'm open-minded about it and I sincerely want to know if I'm missing a crucial point about extends. It seems like you might be thinking about ways of using it that hadn't occurred to me before. Can you provide some real-world use cases where this is a good practice? Maybe link to a gist?
Some quotes from the write up "A problem of using a standard class selector as your @extend identifier is that you extend any styles that feature that selector anywhere in your Sass.", and "To me, I think it would be better that when you extend a selector, you only extend that specific selector."
And there are a number of other blogs, discussions and stackoverflow answers that state the same things. And usually the spirit of the opinion on SASS extends can be summed up by another quote from that link: "I’m not convinced I like that @extends work like this but that’s how it is and it’s better to know exactly how it works."
I think you are jumping in on a discussion and have missed a little of the context here. We have 3 issues really:
LESS is not adding complex selectors (eg .compound.selectors) to the tree... which I consider a bug and should be fixed immediately. The regex is too simple... we should borrow code from the sizzle engine to fix this.
The :exend feature does not extend a selector within media queries... which kinda makes the feature a little useless.
An :extend within a media query is extending a non-media query selector... which is wrong.
I would like to take this opportunity to say more-specific selectors should not get extended in the way that SASS does. For example, in the example below, the .header .selector should NOT get extended (in my opinion):
You should be able to pass ANY valid CSS selector to the :extend function. This is currently not possible and is a bug. This also prevents classical "embeds" from working:
.some-selector {
.some.other-selector; /* This does not work, but it should */
}
Every instance of the exact selector should get extended, whether it's within media queries or not. In my orignal post at the very top, I should be able to :extend(.container), but currently only the non-media query definition gets extended.
Unlink SASS, "more specific" instances of the selector should be left alone (eg .header .selector example above).
An :extend which occurs within a media query would need to smart-copy the actually css rules from other matching media queries (see my last comment for an example of this).
I would love to talk about this over phone and then summarize here. Feel free to call if you want:
six one five-260-2411
I'm just catching up to this discussion, just wanted to first add a +1 for one point:
"I would like to take this opportunity to say more-specific selectors should not get extended in the way that SASS does. For example, in the example below, the .header .selector should NOT get extended (in my opinion):"
Correct. .selector and .header .selector are not used in the same way. It should be an exact string match. If I'm matching .selector it should only extend (add properties to) that class and that class only. And then, of course, it's up to the browser to inherit appropriately into .header .selector.
The only way it should extend both selectors within their definitions would be something like this:
@DesignByOnyx, I misunderstood your point because of the statement "so that all selector patterns get matched", which I interpreted as saying that you wanted SASS-like extends. I now understand that you are not saying to extend .some-selector to all selector patterns of .some-selector, but what you were saying (and had said very clearly earlier) was that when you target any give selector pattern, even if it happens to be a compound selector, like .selector-one.selector-two, it should just work. If this is indeed what you're saying (and is is the same as @MatthewDL is saying), then + 1 and I agree completely. Sorry for the confusion... I got hung up on that statement, even when I tried to re-read it to make sense of the point.
I doesn't help that we're discussing two issues here. One for how :extend handles selector patterns, and one for how :extend is broken in media queries. I would suggest splitting these issues apart so that discussion on either stays focused.
Thanks for the remarks. I think you understand me more clearly now. Sorry for the confusing wording. I agree that we should only be focused on making :extend work the way we think it should across media queries.
The other [less relevant] issue has to deal with LESS's selector engine not recognizing all valid CSS selectors... which is a separate issue but should get fixed immediately. The :extend functionality will simply benefit from this fix as would the rest of the LESS's functionality. This is the fix which I think should take inspiration from the sizzle selector engine. Just a thought.
So, now we are all on the same page. There are two different use cases to consider:
A simple :extend which takes place outside of a media query. This one is simple, as all instances of the selector should get extended... whether in a media query or not.
An :extend which takes place within a media query. This is very complex as the compiler would need to copy styles from other media queries and compile them within the given media query. See my previous comment about this scenario.
@DesignByOnyx would you mind creating another issue for :extend within media queries? We should rename this one too so it can be prioritized and others can add their thoughts.
I thought the main point of extend was where you had a library of css targeting one class, and you had html you were restricted on changing with a different class.. so if I want everywhere that matches .selector to match .something-else then I do the above so that I get
when talking about not wanting something to happen - please could you clarify why you don't want it to happen and what your particular use-case for the extend is?
see #1165 for a discussion of extend around media queries. I don't think we have it nailed down in this discussion exactly what it should do when you use extend inside a media query.
I thought the main point of extend was where you had a library of css targeting one class, and you had html you were restricted on changing with a different class.. so if I want everywhere that matches .selector to match .something-else then I do the above so that...
Maybe we are saying the same thing, but since @agatronic made his comment, I want to be clear:
This one is simple, as all instances of the selector should get extended... whether in a media query or not.
To clarify, you only mean "exact instances" (as you said further above) - I'm going to give examples for this below. Correct me if I'm wrong because this isn't how less.js works today, and I believe it's what Luke is asking for additional clarification on.
IMHO :extend should be fixed to act like the direct inverse of a mixin. If I use a mixin on a selector, the selector inherits the properties of that mixin, but the mixin does not extend to every instance of a selector to which it has been applied. I don't think that :extend should be applied to every instance of the selector being extended either.
I don't want to extend the .header, why would it do that? Now, I have to check through my entire library of LESS files to make sure nothing is extending a class I'm about add a "modifier" class to, or that class will extended as well. What I really want to get is this:
.sasquatch {
z-index: -1;
}
.sasquatch.fur {
color: brown;
background: brown;
}
.yeti,
.sasquatch {
height: really tall;
visibility: camouflaged;
}
// So far, so good. All true..yeti.fur,
.sasquatch.fur {
color: white; // Wait, what?! okay this is not goodbackground: white; // sasquatches need dark backgrounds to hide. damn you cascade, and damn you extends!
}
Too bad we can't do this: .sasquatch:extend:not(.yeti .fur) {}
Because now our friend is in danger:
.hunter:target:only-of-type[class*="-hominid"] {
// Why must he be this way? What's wrong with hunting less endearing species, like pandas?content: "Success"attr(data-status);
}
And then:
.sasquatch:last-of-type {
content: "unfortunately";
display: never again;
}
No more sasquatches. Shame. All because of the unintended consequences of extending all instances of a selector.
I think I see your point. In your shape circle example, If I wanted header to be black I would just set the class name to "shape circle".. where as extend would be useful If I wanted to extract shape's properties without including any other sub properties?
I definitely think we should limit things with extend as much as possible.. that way we can see peoples reaction to it and the use-cases that come up and extend (ha) the behaviour from there.. if we go all out from the start we might end up with something useless.
.a { .b & .c { // shouldn't match
.a { .b & { .c { // should match
:extend(.b .a deep)
is a good example btw. of two selectors that should match/notmatch with @MatthewDL's interpretation of deep, but I think are going to be impossible to tell apart in the current code.
So we agree that your way would not match .button .c and my way does. I think we both understand why we each hold the opinion that we do. Hand shake... moving forward towards reconciliation.
For the sake of conversation, let's consider all selectors where .button is the left-most part of the selector as the "base class" for all things .button (remember that every <element class="button" /> will get these base styles). By my thinking, if something deep extends.button, all "base class" properties and child properties should get extended (I think I have made this clear, don't mean to beat the point).
In the example above, if "prop3" should no longer be part of the base class, then I need to do a multi-shallow-extend sort of like @jonschlinkert argued at the beginning of this thread:
test:extend(.button, button .a, .button .b) { }
... OR give it a new "base class": #main .button .c
You are correct that .b .a would match. The "deep" modifier would only be useful if there were actually some "deeper" styles to extend:
.a { .a { .b & { .c {
:extend(.b .a deep)
Now let me address your next example:
.a { .b & .c { // shouldn't match
.a { .b & { .c { // should match
:extend(.b .a deep)
I disagree and think BOTH should match... again because the fact that .c is nested in one but not the other is merely a preference. In both cases, .b .a is the left-most part of the selector... the "base class" if you will.
Here is how I view the "any/exact" modifiers in lay terms:
:extend(.b .a exact) - find all selectors where .b .a is the left-most part of the final selector
:extend(.b .a any) - find all selectors where .b .a is ANYwhere in the final selector (beginning, middle, or end).
@DesignByOnyx I have edited my last example post to make it clearer the example is not what I think should happen but instead two selectors that the current code can't differentiate.. I agree with you, that both should match.
"your view" of "any/exact" is extremely confusing to the whole picture. The original "approved" idea was two properties, shallow/deep and any/exact. exact means matches entire selector only and nothing below it - something I think is a great innovation in our syntax... we do not want to redefine it to mean the "left-most part".
We are talking about the definition of shallow/deep which are sub options. When considering how extend works on the output selectors (e.g. how @DesignByOnyx wants it to work) it essentially boils down to whether you allow parts before or after - those two booleans give you the 4 names.. this was my reason for suggesting that, assuming we were to go with what you want, we must rename the options because at the moment they are confusing. Perhaps this is supported by the fact you confused them above?
@MatthewDL I forgot to also mention that your variable example works for variables, but not for mixins
.button .a { } // intentionally refactored / removed to not be included on the extend
is something I would recommend people not to do - how come I want to extend button and all classes related later classes but the target decides it doesn't want to be extended when used to select a child link? Shouldn't it be the extender that decides what it wants to target (with the shallow/deep options). By treating the selectors differently we are putting in this extra bit of weird behaviour over how selectors are matched and putting the control over that with whom-ever writes the source selector
I am worried this debate will go on forever (there seems to be a large amount of content generated from misunderstanding) and am still fond of only supporting no options (exact) and all, using @MatthewDL definition that everyone agreed with way back on the thread.. we can always see what feedback we get from that and leave this open to a later version.
Man I don't understand how we got so off base. You make the following comment:
exact means matches entire selector only and nothing below it.
Correct.
THEN, if someone passes "deep", it will match items below it, right? By original definition, "deep" should extend all nested selectors/properties. I consider .a, .b, and .c to be "nested" below the button here... despite the syntax... and this point is really important to me:
Now, I never... ever... ever took "deep" OR "exact" to mean that it would match .button in the following context, and I cannot understand how you can think that it should or that it's even useful:
If you wanted to match .button in the above example, you should have to do one of two things (note, I am leaving out "deep" because I am just trying to match .button right now):
:extend(#header .button) { } - This is very explicit... no confusion
extend(.button any) { } - This is very willy nilly "extend everything", but useful is some situations
.button {
.a { prop1:prop1; }
.b { prop2:prop2; }
}
.button .c { prop3:prop3; }
#header {
.button {
.a { prop4:prop4; }
}
}
/* Make all call-to-action links look like buttons */
.call-to-action a:extend(.button deep) { /* Props 1-3 */ }
/* Make this link look just like the header button even though it's not in the header */
.cta-2 a:extend(#header .button deep) { /* Prop4 */ }
/* Make all submit buttons get the same styles as .button */
input[type="submit"]:extend(.button deep any) { /* Props 1-4 */ }
If you still don't agree, then I am done with this thread and this whole discussion was pointless for me. This is my last comment on this issue. Please re-read my last several comments if you still need clarification on how I see it.
Pardon me, but what is going on here? Why can't we just leave this pseudo-selector idea and all the black magic aside, do only exact selector matches (like stylus) and implement the obvious:
.button { ... }
.action {
extend(.button);
}
// or this, a nice complement to standard mixin syntax
.action {
.button+;
}
I haven't read the 396 posts in this issue, so I might be just pissing all over the work done so far, but I feel like just leaving the building. It's been a couple years since this surfaced as a needed feature.
This conversation has gone on this long because the core team cares so much about everyone's expectations. If you read through the discussions you would see that the discussion has gone this long because others disagreed with your point (even suggesting we do "exact match" like Stylus' implementation was made. by me actually).
Why can't we just leave this pseudo-selector idea and all the black magic aside
That boat has sailed. It was discussed at length by a number of people including cloudhead. More information can be found on the original request for extend, submitted just over a year ago: #509.
I feel like just leaving the building. It's been a couple years since this surfaced as a needed feature.
I hear you about the frustration, I felt like leaving the building too before @MatthewDL and @lukeapage graciously stepped up and turned the project around, gratis. Remember that we're all open source contributors giving to this is what little free time we have.
Stay passionate about seeing progress with LESS, but be patient. We're going to get this resolved.
I was thinking around it, sorry still in reading all the posts, so would probably miss something, as my point possible way is extending vocabulary, like Luke suggested with from/upto, let's say something like
.button {
.a { prop1:prop1; }
.b { prop2:prop2; }
}
.button .c { prop3:prop3; }
.test:extend(.button before .c) // before/after sounds familiar, by nature deep and exact, though it might be fun to have something shallow here;)
I also see reason in scope behavior suggested by Matthew, though this approach looks less attractive in situation when you need make quick patch to someone's spagetti code and you are not entirely sure about what's the code structure is, if it is consistent or not, and so you will have to go into deeper refactoring.
And some thoughts about any keyword as I got it, sorry for repeating it.
@jonschlinkert yes, I followed that issue. at some point it was simply arbitrarily decided that the syntax was done, just like it had been changed to ++ a few months earlier with a pair of opinions. I don't see how a pre-processor directive belongs amongst a CSS selector. It has no parallel to jQuery filters or any pseudo-selectors as hinted in that discussion.
While the original SASS-like +.button; syntax was certainly confusing, putting the + at the end is nice: .button; copies/beams down properties, .button+; adds/beams up the selector, and could be just syntax sugar for a extend(.button) method. It's current a syntax error, so not ambiguous at all.
Anyway, I know I'm late to the party. As long as &:extend is supported and the any, deep insanity is ignored I think everyone will be happy :)
Activity
DesignByOnyx commentedon Jan 31, 2013
I have a request for the moderator so that someone doesn't try and use my code in their projects. It turns out that specifying media queries in
remdoesn't work in some browsers (Safari, iPad Chrome, iPad Safari, etc). This was an experimental feature I was testing. Could you please change the values in the media query definitions toem. The.containerwidth and margins can still userem(and should).matthew-dean commentedon Jan 31, 2013
@DesignByOnyx Updated.
DesignByOnyx commentedon Feb 1, 2013
And to complicate matters more, here's another weird case:
The situation here is that
.some-elementalways gets the shared styles as opposed to only when the media query is active:The only real solution I see here is to abandon
:extendwithin media queries and resort to the classic include:lukeapage commentedon Feb 2, 2013
issue 2 is just a missing feature.. surprised it parses as the contents of
:extend(should be a single class or node selector. maybe a feature request for the future.media queries.
.shared-style;but in more complex examples it would pull in the bits of the selector tooDesignByOnyx commentedon Feb 3, 2013
Regarding your point number 1 - I think selector matching isn't a feature but a requirement. Can we not pull parts of sizzle in so that all selector patterns get matched?
Regarding your point 2 about copying the code - I agree, but the problem gets very complicated if you have something like this, as the parser will have to be smart enough to apply styles from other media queries:
-- take note of the single
:extendbelow, then take note of the comments --jonschlinkert commentedon Feb 3, 2013
@DesignByOnyx, I'm going to have to spend more time with your use case, but honestly after using SASS extends and doing a lot of testing on extends myself, I'm not sure I agree with any of your point(s) about number 1 (that's the only part I'm responding to here). The "comprehensive selector matching" was something I personally don't like - and didn't like about SASS. Why would you want to extend to every selector pattern? I really am curious, that's not intended as a statement...
From my standpoint, the Less.js implementation and syntax for extends are far more powerful than SASS and allow you to use a surgical "laser" approach with design practices, rather than using than a shotgun blast. Seems like the "sizzle" is very specifically the ability choose what you want to extend.
However, I'm open-minded about it and I sincerely want to know if I'm missing a crucial point about extends. It seems like you might be thinking about ways of using it that hadn't occurred to me before. Can you provide some real-world use cases where this is a good practice? Maybe link to a gist?
In the meantime, here is write up about learning SASS extends that brings some important points to light: http://8gramgorilla.com/mastering-sass-extends-and-placeholders/
Some quotes from the write up "A problem of using a standard class selector as your @extend identifier is that you extend any styles that feature that selector anywhere in your Sass.", and "To me, I think it would be better that when you extend a selector, you only extend that specific selector."
And there are a number of other blogs, discussions and stackoverflow answers that state the same things. And usually the spirit of the opinion on SASS extends can be summed up by another quote from that link: "I’m not convinced I like that @extends work like this but that’s how it is and it’s better to know exactly how it works."
DesignByOnyx commentedon Feb 6, 2013
I think you are jumping in on a discussion and have missed a little of the context here. We have 3 issues really:
:exendfeature does not extend a selector within media queries... which kinda makes the feature a little useless.:extendwithin a media query is extending a non-media query selector... which is wrong.I would like to take this opportunity to say more-specific selectors should not get extended in the way that SASS does. For example, in the example below, the
.header .selectorshould NOT get extended (in my opinion):However, in the following example, the
.header .selectorshould get extended, but not the stand-alone (less-specific).selector:So here is what I think should happen:
:extendfunction. This is currently not possible and is a bug. This also prevents classical "embeds" from working::extend(.container), but currently only the non-media query definition gets extended..header .selectorexample above).:extendwhich occurs within a media query would need to smart-copy the actually css rules from other matching media queries (see my last comment for an example of this).I would love to talk about this over phone and then summarize here. Feel free to call if you want:
six one five-260-2411
matthew-dean commentedon Feb 6, 2013
I'm just catching up to this discussion, just wanted to first add a +1 for one point:
"I would like to take this opportunity to say more-specific selectors should not get extended in the way that SASS does. For example, in the example below, the .header .selector should NOT get extended (in my opinion):"
Correct.
.selectorand.header .selectorare not used in the same way. It should be an exact string match. If I'm matching.selectorit should only extend (add properties to) that class and that class only. And then, of course, it's up to the browser to inherit appropriately into.header .selector.The only way it should extend both selectors within their definitions would be something like this:
jonschlinkert commentedon Feb 7, 2013
@DesignByOnyx, I misunderstood your point because of the statement "so that all selector patterns get matched", which I interpreted as saying that you wanted SASS-like extends. I now understand that you are not saying to extend
.some-selectorto all selector patterns of.some-selector, but what you were saying (and had said very clearly earlier) was that when you target any give selector pattern, even if it happens to be a compound selector, like.selector-one.selector-two, it should just work. If this is indeed what you're saying (and is is the same as @MatthewDL is saying), then + 1 and I agree completely. Sorry for the confusion... I got hung up on that statement, even when I tried to re-read it to make sense of the point.I doesn't help that we're discussing two issues here. One for how
:extendhandles selector patterns, and one for how:extendis broken in media queries. I would suggest splitting these issues apart so that discussion on either stays focused.DesignByOnyx commentedon Feb 7, 2013
Thanks for the remarks. I think you understand me more clearly now. Sorry for the confusing wording. I agree that we should only be focused on making
:extendwork the way we think it should across media queries.The other [less relevant] issue has to deal with LESS's selector engine not recognizing all valid CSS selectors... which is a separate issue but should get fixed immediately. The
:extendfunctionality will simply benefit from this fix as would the rest of the LESS's functionality. This is the fix which I think should take inspiration from the sizzle selector engine. Just a thought.So, now we are all on the same page. There are two different use cases to consider:
A simple
:extendwhich takes place outside of a media query. This one is simple, as all instances of the selector should get extended... whether in a media query or not.An
:extendwhich takes place within a media query. This is very complex as the compiler would need to copy styles from other media queries and compile them within the given media query. See my previous comment about this scenario.jonschlinkert commentedon Feb 7, 2013
@DesignByOnyx would you mind creating another issue for :extend within media queries? We should rename this one too so it can be prioritized and others can add their thoughts.
lukeapage commentedon Feb 7, 2013
regarding this point
should not extend
.header .selectorI thought the main point of extend was where you had a library of css targeting one class, and you had html you were restricted on changing with a different class.. so if I want everywhere that matches
.selectorto match.something-elsethen I do the above so that I getwhen talking about not wanting something to happen - please could you clarify why you don't want it to happen and what your particular use-case for the extend is?
lukeapage commentedon Feb 7, 2013
see #1165 for a discussion of extend around media queries. I don't think we have it nailed down in this discussion exactly what it should do when you use extend inside a media query.
jonschlinkert commentedon Feb 7, 2013
@agatronic
@DesignByOnyx
Maybe we are saying the same thing, but since @agatronic made his comment, I want to be clear:
To clarify, you only mean "exact instances" (as you said further above) - I'm going to give examples for this below. Correct me if I'm wrong because this isn't how less.js works today, and I believe it's what Luke is asking for additional clarification on.
IMHO
:extendshould be fixed to act like the direct inverse of a mixin. If I use a mixin on a selector, the selector inherits the properties of that mixin, but the mixin does not extend to every instance of a selector to which it has been applied. I don't think that:extendshould be applied to every instance of the selector being extended either.So if I do this:
I would expect to see this:
not this...
If I wanted the last result I would do this:
To expand the example, currently I can do the following with
:extends:and it compiles to this:
I don't want to extend the
.header, why would it do that? Now, I have to check through my entire library of LESS files to make sure nothing is extending a class I'm about add a "modifier" class to, or that class will extended as well. What I really want to get is this:Let's take a real-world example though, something more concrete, so you can see how this is effecting the wildlife:
Today it compiles to this:
Too bad we can't do this:
.sasquatch:extend:not(.yeti .fur) {}Because now our friend is in danger:
And then:
No more sasquatches. Shame. All because of the unintended consequences of extending all instances of a selector.
lukeapage commentedon Feb 7, 2013
I think I see your point. In your shape circle example, If I wanted header to be black I would just set the class name to "shape circle".. where as extend would be useful If I wanted to extract shape's properties without including any other sub properties?
I definitely think we should limit things with extend as much as possible.. that way we can see peoples reaction to it and the use-cases that come up and extend (ha) the behaviour from there.. if we go all out from the start we might end up with something useless.
129 remaining items
lukeapage commentedon Mar 5, 2013
is a good example btw. of two selectors that should match/notmatch with @MatthewDL's interpretation of deep, but I think are going to be impossible to tell apart in the current code.
DesignByOnyx commentedon Mar 5, 2013
@MatthewDL - you are correct, we need to come to some sort of consensus. Let's take a simple example we have already been using:
So we agree that your way would not match
.button .cand my way does. I think we both understand why we each hold the opinion that we do. Hand shake... moving forward towards reconciliation.For the sake of conversation, let's consider all selectors where
.buttonis the left-most part of the selector as the "base class" for all things.button(remember that every<element class="button" />will get these base styles). By my thinking, if something deep extends.button, all "base class" properties and child properties should get extended (I think I have made this clear, don't mean to beat the point).In the example above, if "prop3" should no longer be part of the base class, then I need to do a multi-shallow-extend sort of like @jonschlinkert argued at the beginning of this thread:
... OR give it a new "base class":
#main .button .c@lukeapage - you provided the following example:
You are correct that
.b .awould match. The "deep" modifier would only be useful if there were actually some "deeper" styles to extend:Now let me address your next example:
I disagree and think BOTH should match... again because the fact that
.cis nested in one but not the other is merely a preference. In both cases,.b .ais the left-most part of the selector... the "base class" if you will.Here is how I view the "any/exact" modifiers in lay terms:
:extend(.b .a exact)- find all selectors where.b .ais the left-most part of the final selector:extend(.b .a any)- find all selectors where.b .ais ANYwhere in the final selector (beginning, middle, or end).lukeapage commentedon Mar 5, 2013
@DesignByOnyx I have edited my last example post to make it clearer the example is not what I think should happen but instead two selectors that the current code can't differentiate.. I agree with you, that both should match.
"your view" of "any/exact" is extremely confusing to the whole picture. The original "approved" idea was two properties, shallow/deep and any/exact. exact means matches entire selector only and nothing below it - something I think is a great innovation in our syntax... we do not want to redefine it to mean the "left-most part".
We are talking about the definition of shallow/deep which are sub options. When considering how extend works on the output selectors (e.g. how @DesignByOnyx wants it to work) it essentially boils down to whether you allow parts before or after - those two booleans give you the 4 names.. this was my reason for suggesting that, assuming we were to go with what you want, we must rename the options because at the moment they are confusing. Perhaps this is supported by the fact you confused them above?
@MatthewDL I forgot to also mention that your variable example works for variables, but not for mixins
also I kind of think that doing this
is something I would recommend people not to do - how come I want to extend button and all classes related later classes but the target decides it doesn't want to be extended when used to select a child link? Shouldn't it be the extender that decides what it wants to target (with the shallow/deep options). By treating the selectors differently we are putting in this extra bit of weird behaviour over how selectors are matched and putting the control over that with whom-ever writes the source selector
I am worried this debate will go on forever (there seems to be a large amount of content generated from misunderstanding) and am still fond of only supporting no options (exact) and all, using @MatthewDL definition that everyone agreed with way back on the thread.. we can always see what feedback we get from that and leave this open to a later version.
DesignByOnyx commentedon Mar 6, 2013
Man I don't understand how we got so off base. You make the following comment:
Correct.
THEN, if someone passes "deep", it will match items below it, right? By original definition, "deep" should extend all nested selectors/properties. I consider
.a,.b, and.cto be "nested" below the button here... despite the syntax... and this point is really important to me:Now, I never... ever... ever took "deep" OR "exact" to mean that it would match
.buttonin the following context, and I cannot understand how you can think that it should or that it's even useful:If you wanted to match
.buttonin the above example, you should have to do one of two things (note, I am leaving out "deep" because I am just trying to match.buttonright now)::extend(#header .button) { }- This is very explicit... no confusionextend(.button any) { }- This is very willy nilly "extend everything", but useful is some situationsPlease think about the DOM:
And this LESS:
If you still don't agree, then I am done with this thread and this whole discussion was pointless for me. This is my last comment on this issue. Please re-read my last several comments if you still need clarification on how I see it.
ricardobeat commentedon Mar 6, 2013
Pardon me, but what is going on here? Why can't we just leave this pseudo-selector idea and all the black magic aside, do only exact selector matches (like stylus) and implement the obvious:
I haven't read the 396 posts in this issue, so I might be just pissing all over the work done so far, but I feel like just leaving the building. It's been a couple years since this surfaced as a needed feature.
jonschlinkert commentedon Mar 6, 2013
@ricardobeat noted, and we agree.
This conversation has gone on this long because the core team cares so much about everyone's expectations. If you read through the discussions you would see that the discussion has gone this long because others disagreed with your point (even suggesting we do "exact match" like Stylus' implementation was made. by me actually).
That boat has sailed. It was discussed at length by a number of people including cloudhead. More information can be found on the original request for extend, submitted just over a year ago: #509.
I hear you about the frustration, I felt like leaving the building too before @MatthewDL and @lukeapage graciously stepped up and turned the project around, gratis. Remember that we're all open source contributors giving to this is what little free time we have.
Stay passionate about seeing progress with LESS, but be patient. We're going to get this resolved.
dmi3y commentedon Mar 6, 2013
I was thinking around it, sorry still in reading all the posts, so would probably miss something, as my point possible way is extending vocabulary, like Luke suggested with from/upto, let's say something like
I also see reason in scope behavior suggested by Matthew, though this approach looks less attractive in situation when you need make quick patch to someone's spagetti code and you are not entirely sure about what's the code structure is, if it is consistent or not, and so you will have to go into deeper refactoring.
And some thoughts about
anykeyword as I got it, sorry for repeating it.makes class substitution?
or just replacement of the whole selector?
I think it is first, although could you think over situations when the latter could be applicable?
dmi3y commentedon Mar 6, 2013
erh, suppose, because it is not so funny;) (gone to prepare css/html/javascript elecsir:D)
PS: I am sorry for off top, if you feel it is insulting just let me know and I will remove it.
ricardobeat commentedon Mar 6, 2013
@jonschlinkert yes, I followed that issue. at some point it was simply arbitrarily decided that the syntax was done, just like it had been changed to
++a few months earlier with a pair of opinions. I don't see how a pre-processor directive belongs amongst a CSS selector. It has no parallel to jQuery filters or any pseudo-selectors as hinted in that discussion.While the original SASS-like
+.button;syntax was certainly confusing, putting the+at the end is nice:.button;copies/beams down properties,.button+;adds/beams up the selector, and could be just syntax sugar for aextend(.button)method. It's current a syntax error, so not ambiguous at all.Anyway, I know I'm late to the party. As long as
&:extendis supported and theany, deepinsanity is ignored I think everyone will be happy :)Merg1255 commentedon Mar 6, 2013
since this is the only remaining issue for 1.4, do we have any news on where about it will be released?..
lukeapage commentedon Mar 7, 2013
We (me, Jon, Matthew) have decided to go with exact (no options) and all for now and revisit this after release and outside reactions.
You can try this out today on less2css.org (select drop down then alpha) and I'm planning on releasing a beta today if I finish chaining.
jonschlinkert commentedon Mar 7, 2013
👍 nice job, thank you @lukeapage.
Merg1255 commentedon Mar 7, 2013
thank you @lukeapage ! :)
lukeapage commentedon Sep 26, 2014
Yes it did.
http://lesscss.org/features/
Read the extend section