postcss-selector-matches icon indicating copy to clipboard operation
postcss-selector-matches copied to clipboard

:matches(element)

Open stevenvachon opened this issue 9 years ago • 9 comments

.class {
  &:matches(element) {
    property: value;
  }
}

produces:

.classelement {
  property: value;
}

when it should produce:

element.class {
  property: value;
}

Tied to postcss-cssnext#287.

stevenvachon avatar Jun 16 '16 12:06 stevenvachon

PR welcome :)

MoOx avatar Jun 16 '16 12:06 MoOx

I haven't worked with PostCSS under the hood, so I probably won't have the time to help much. Have even been having difficulty finding time for my own projects lately.

stevenvachon avatar Jun 16 '16 13:06 stevenvachon

Have even been having difficulty finding time for my own projects lately.

My life :D

MoOx avatar Jun 16 '16 13:06 MoOx

Hi,

I do not know is the right way to ask this in this issue or this repository.

Howether, I started to put my interest on the cssnext features. And the matches specs is unclear.

I quickly understood that :matches() is used to avoid the overuse of

p.foo, p.bar, p.baz, p.[...] {}

/* reduced to */
p:matches(.foo, .bar, .baz) {}

But.. is it possible to use :matches() in this scenario ?

form > *:matches(button, a.button, input[type=button])

/* or */
form  matches(> button, > a.button, > input[type=button])

/* instead of */
form > button,
form > a.button,
form > input[type=button])
{}

Cheer,

Swizz avatar Jul 20 '16 10:07 Swizz

Closed by #8

MoOx avatar Sep 06 '16 05:09 MoOx

@MoOx @yordis I'm still experiencing issues with this, but with a more specific case now:

.namespace {
  &:not(.classA, .classB) {
    &:matches(element) {
      property: value;
    }
  }
}

is resulting in:

.namespace:not(.classA):not(.classB)element {
  property: value;
}

Meanwhile, this:

.namespace {
  &:not(.classA) {
    &:matches(element) {
      property: value;
    }
  }
}

compiles correctly into:

element.namespace:not(.classA) {
  property: value;
}

Here's another test case:

.list {
  &:matches(ol, ul) {
    property: value;
    li {
      property: value;
    }
  }

  &:matches(ol) {
    property: value;
    li {
      property: value;
    }
  }
}

stevenvachon avatar Oct 20 '16 17:10 stevenvachon

Feel free to make a PR to fix this :)

MoOx avatar Oct 21 '16 05:10 MoOx

I also think that cases like p:matches(a) should simply be removed rather than concatenating like the README states.

clarfonthey avatar Feb 15 '18 20:02 clarfonthey

I'm also facing an issue with a (quite simple) element selector.

.foo > .bar:matches(a) {
  color: red;
}

compiles to

.foo > .bara {
  color: red;
}

instead of

.foo > a.bar {
  color: red;
}

SassNinja avatar Dec 12 '18 17:12 SassNinja