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.

Nice to have `&&` references parent's parent

See original GitHub issue

I’m writing code where I want to store a component’s state as a bem modifier on the container. Right now I can’t use the new &--... nested with &-... to do so. Therefore I propose to add a double ampersand to reference the parent’s parent, and perhaps &(n) to continue upward traversal.

Example:

.Block {
  &-element { … }

  &--modifier {
    &&-element { … }
  }
}

would compile to

.Block-element { … }
.Block--modifier .Block-element { … }

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

40reactions
cimmanoncommented, Aug 5, 2015

Sass already offers the ability to do what you’re asking.

.Block {
  $p: &;
  &-element { /* */ }

  &--modifier {
    #{$p}-element { /* */ }
  }
}

Understanding the & is a difficult concept for a lot of people (a lot of novices mistakenly believe that it only references the previous level of nesting rather than the entire resolved selector). Adding a double ampersand would only further confuse novices.

Your second suggestion makes absolutely no sense and would be a backwards incompatible change for users who already use the parent selector in its current form.

4reactions
sbussardcommented, Aug 5, 2015

Apparently I misunderstood what & is used for. On the other hand it looks like the current behavior of sass is counterintuitive. If & references the root parent, then it seems like the intuitive behavior would be this:

.Block {
  &-element { … }
  &--modifier {
    &-element { … }
  }
}

would compile to:

.Block-element { … }
.Block--modifier .Block-element { … }

instead of the current:

.Block-element { … }
.Block--modifier-element { … }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Do You Give Parent References? — Taking Care of Business
Have you ever been asked to give references by parents looking for a family child care provider?It's not that common for parents to...
Read more >
Should you put your father as a reference if you worked for his ...
References should at least appear to be unbiased. Choose someone else, preferably your immediate supervisor or someone well-acquainted with your work.
Read more >
No, you cannot use your mother as a professional reference!
No, you cannot use your mother as a professional reference !
Read more >
Character Reference Letter for Court: Child Custody Template
A character reference letter gives the judge insight into the case by offering a third party's perspective on the parent's relationship with the...
Read more >
Is it bad to put your parents as references, even if they ... - Reddit
In general, using relatives/significant others is going to look bad since it's not as if a potential employer expects your parents to give...
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