Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Using multiple custom-selectors in one selector does not work #19

Closed
topaxi opened this issue Jun 23, 2015 · 14 comments · Fixed by #27
Closed

Using multiple custom-selectors in one selector does not work #19

topaxi opened this issue Jun 23, 2015 · 14 comments · Fixed by #27
Assignees
Labels

Comments

@topaxi
Copy link

topaxi commented Jun 23, 2015

For example this:

@custom-selector :--button-types
  .btn-primary,
  .btn-success,
  .btn-info,
  .btn-warning,
  .btn-danger;

:--button-types, :--button-types:active {
  color: white;
}

compiles to this:

.btn-primary, :--button-types:active,
.btn-success, :--button-types:active,
.btn-info, :--button-types:active,
.btn-warning, :--button-types:active,
.btn-danger, :--button-types:active {
  color: white;
}

instead of this:

.btn-primary, .btn-primary:active,
.btn-success, .btn-success:active,
.btn-info, .btn-info:active,
.btn-warning, .btn-warning:active,
.btn-danger, .btn-danger:active {
  color: white;
}
@MoOx MoOx added the bug label Jun 23, 2015
@yisibl
Copy link
Contributor

yisibl commented Jun 23, 2015

@MoOx
Copy link
Contributor

MoOx commented Jun 23, 2015

Nice :)

@topaxi
Copy link
Author

topaxi commented Jun 24, 2015

I'm pretty sure this worked before, might be a cssnext update that caused this but:

@custom-selector :--foobar .foo, .bar;
@custom-selector :--baz .baz;

:--foobar > :--baz {
  color: red;
}

Isn't working for me anymore and now produces:

.foo,
.bar {
  color: red;
}

Instead of:

.foo > .baz,
.bar > .baz {
  color: red;
}

Is this the same limitation or just a regression?

cssnext 1.7.1 with postcss-custom-selectors 2.1.0

@topaxi
Copy link
Author

topaxi commented Jun 24, 2015

Okay the comment above is definitely a cssnext problem, seems to be working with plain postcss-custom-selectors.

@MoOx
Copy link
Contributor

MoOx commented Jun 24, 2015

@topaxi
Copy link
Author

topaxi commented Jun 26, 2015

So the case above was a playground/firefox issue. I tried to simplify the selectors I got and now have a failing case which definitely fails in postcss-custom-selectors and probably isn't related to cssnext.

input.css:

@custom-selector :--fizzbuzz .fizz, .buzz;
@custom-selector :--foobar .foo, .bar;

:--fizzbuzz > :--foobar {
  color: red;
}

output.css:

.fizz > .foo,
.fizz > .bar,
.buzz > .foo,
.buzz > .bar {
  color: red;
}

actual.css:

.fizz > .foo,,
.fizz > .bar,
.buzz > .foo,

.buzz > .bar {
  color: red;
}

@MoOx
Copy link
Contributor

MoOx commented Jun 29, 2015

It seems related to this part https://github.com/postcss/postcss-custom-selectors/blob/e020e3220644d1975b4dc7102d1acb1e0bec38a0/index.js#L21 which does not reset the list for each plugin executions

@MoOx
Copy link
Contributor

MoOx commented Jul 4, 2015

I am on working on this bug.

@MoOx
Copy link
Contributor

MoOx commented Jul 10, 2015

@yisibl I am going to completely rewrite this plugin with the codebase of postcss-selector-matches (so using babel). This will be better, are you ok with that?

@hgl
Copy link

hgl commented Jul 10, 2015

+1, Mama no longer has to worry that I don't use es 2015 often enough. :)

@MoOx Possible to allow cssnext config file to be written in es 2015 too? Maybe pass that file to babel instead of requiring it directly?

@topaxi
Copy link
Author

topaxi commented Jul 10, 2015

I think this is the right way to do it, the custom selector spec even says that it expands into :matches() selectors.

@yisibl
Copy link
Contributor

yisibl commented Jul 10, 2015

@MoOx This is the reason why I had to use postcss-selector-matches before. #16

You can rest assured that you can change it.

@MoOx
Copy link
Contributor

MoOx commented Jul 13, 2015

Almost done. PR is coming really soon. Some fixes will be pushed in postcss-selector-matches at the same time :)

MoOx added a commit that referenced this issue Jul 14, 2015
This commit include a refactoring based on postcss-selector-matches and
add the ability to limit the transformation to :matches() usage.
Also in this commit:

- add eslint
- rewrite using babel (es6/7)
- fixtures files removed in favor of es6 template string
- should also fix some weird “undefined” warnings

Close #19
@MoOx
Copy link
Contributor

MoOx commented Jul 14, 2015

Complete rewrite has just been pushed as a PR #27

MoOx added a commit that referenced this issue Jul 14, 2015
This commit include a refactoring based on postcss-selector-matches and
add the ability to limit the transformation to :matches() usage.
Also in this commit:

- add eslint
- rewrite using babel (es6/7)
- fixtures files removed in favor of es6 template string
- should also fix some weird “undefined” warnings

Close #19
romainmenke pushed a commit to csstools/postcss-plugins that referenced this issue Jun 1, 2022
This commit include a refactoring based on postcss-selector-matches and
add the ability to limit the transformation to :matches() usage.
Also in this commit:

- add eslint
- rewrite using babel (es6/7)
- fixtures files removed in favor of es6 template string
- should also fix some weird “undefined” warnings

Close csstools/postcss-custom-selectors#19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants