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

Wrong output when mixing selectors #15

Closed
MoOx opened this issue Jun 2, 2015 · 10 comments
Closed

Wrong output when mixing selectors #15

MoOx opened this issue Jun 2, 2015 · 10 comments
Labels

Comments

@MoOx
Copy link
Contributor

MoOx commented Jun 2, 2015

@custom-selector :--button button, .button;
:--button a, b {}

gives

button a,
.button a, b {}

Which doesn't seems correct. (edit: it is)

This lead to a bug into cssnext where

@custom-selector :--button button, .button;

:--button:matches(:focus) {}

:--button:matches(.is-focused, .is-broken) {}

gives

button:focus,
.button:focus {}

button:matches(.is-focused,
.button.is-focused, button:matches(.is-focused,
.button.is-broken {}

It's probably because this plugin currently use .selector instead of .selectors when playing with selectors :)

Bug reported by @jaredadobe

@MoOx MoOx added the bug label Jun 2, 2015
@jaredadobe
Copy link
Contributor

I am going to take a stab at fixing. Will get a chance in about 2 hours.

@yisibl
Copy link
Contributor

yisibl commented Jun 2, 2015

The specification does not seem this syntax.

But we can think about how to expand it.

@custom-selector = @custom-selector <custom-selector> <selector> ;
<custom-selector> = <custom-arg>? : <extension-name> [ ( <custom-arg>+#? ) ]? ;
<custom-arg> = $ <ident-token> ;

@MoOx
Copy link
Contributor Author

MoOx commented Jun 2, 2015

Oh... In fact I say

button a,
.button a, b {}

was incorrect but it is not.

But the second example with matches is still wrong.
We should throw a exception if spec doesn't allow that, or make it like we might expect:

button:matches(.is-focused,.is-broken),
.button:matches(.is-focused,.is-broken) {}

This way, postcss-selector-matches will be able to do his job.

@yisibl
Copy link
Contributor

yisibl commented Jun 2, 2015

What's the final CSS? Like this?

button.is-focused,
.button.is-focused, button.is-broken,
.button.is-focused, button.is-focused,
.button.is-broken, button.is-broken,
.button.is-broken {}

@MoOx
Copy link
Contributor Author

MoOx commented Jun 2, 2015

This plugin doesn't need to know since postcss-selector-matches will handle to conversion correctly when this one have done his job correctly ;)

(But yes is will look like what you showed)

@jaredadobe
Copy link
Contributor

Working on it now. That is what it should look like.

FYI
here is the test i have added

@custom-selector :--buttons button, .button;

:--buttons:matches(:focus) {
    border: red;
    display: block;
}


:--buttons:matches(:focus, .is-focused) {
    border: red;
    display: block;
}


the output is currently as follows

button:matches(:focus),
.button:matches(:focus) {
    border: red;
    display: block;
}


button:matches(:focus,
.button:matches(:focus, .is-focused) {
    border: red;
    display: block;
}

I am aiming to produce the following as my expected. Let me know if you have any problems with the output

button:matches(:focus),
.button:matches(:focus) {
    border: red;
    display: block;
}


button:matches(:focus, .is-focused),
.button:matches(:focus, .is-focused) {
    border: red;
    display: block;
}

@jaredadobe
Copy link
Contributor

I have a fix, but i would like to try out another solution before opening the PR.

@MoOx
Copy link
Contributor Author

MoOx commented Jun 2, 2015

#5 (comment)

@MoOx
Copy link
Contributor Author

MoOx commented Jun 2, 2015

The last output seems fine.

@jaredadobe
Copy link
Contributor

This can now be closed.

@MoOx MoOx closed this as completed Jun 3, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants