Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested element type selector broken #274

Closed
joernroeder opened this issue Sep 24, 2021 · 7 comments
Closed

nested element type selector broken #274

joernroeder opened this issue Sep 24, 2021 · 7 comments

Comments

@joernroeder
Copy link

I'm upgrading from emotion 10 to 11 (which bumped stylis up) and experiencing some changes in how my "button" selector works which I apply to button and a elements.

.button {
    color: blue

    &:hover, &:focus, &.is-active {
        &:enabled, a& {
            color: red
        }
    }
}

This previously generated the following css

/* for :enabled for <button> elements */
.button:hover:enabled,
.button:focus:enabled,
.button.is-active:enabled,

/* <a> elements styled as buttons */
a.button:hover,
a.button:focus,
a.button.is-active {
    color: red
}

but appends the "tag" selector wrongly

/* for :enabled for <button> elements, all good here */
.button:hover:enabled,
.button:focus:enabled,
.button.is-active:enabled,

/* the <a> element selector gets wrongly appended */
.button:hovera,
.button:focusa,
.button.is-activea {
    color: red
}
@Andarist
Copy link
Collaborator

Testing it on the https://stylis.js.org/ it seems like it works as expected. This might be an issue with Emotion - could you create a full runnable repro case of the problem?

@joernroeder
Copy link
Author

This is the output I am seeing on stylis.js.org which differs but is is not correct either.

Screenshot 2021-09-25 at 09 49 15

Will provide a runnable example later this weekend.

@joernroeder
Copy link
Author

added runnable examples in the issue raised at emotion ☝️

@Andarist
Copy link
Collaborator

Thank you! As to the correct output - remember that on the Stylis docs page everything is implicitly wrapped in [namespace] { /* your css */ } and with that in mind this output looks correct to me:

[namespace] .button {
  color: blue;
}

[namespace] .button:hover:enabled,
[namespace] .button:focus:enabled,
[namespace] .button.is-active:enabled,
a[namespace] .button:hover,
a[namespace] .button:focus,
a[namespace] .button.is-active {
  color: red;
}

I've tried comparing with Sass but it turns out that this is not even a valid Sass because I get this error:

Error: "&" may only used at the beginning of a compound selector

If I just remove the .button wrapping and assume that [namespace] should be where you have used it then we get this:

[namespace] {
  color: blue;
}

[namespace]:hover:enabled,
[namespace]:focus:enabled,
[namespace].is-active:enabled,
a[namespace]:hover,
a[namespace]:focus,
a[namespace].is-active {
  color: red;
}

then this looks exactly the same as your expected output. Could you confirm that? Maybe I'm missing something here.

@joernroeder
Copy link
Author

Hey @Andarist, thanks for looking into it and you're right the following looks like correct. It seems to be a change in emotion which caused my issue then 🤔

Screenshot 2021-09-27 at 21 27 52

@Andarist
Copy link
Collaborator

Thank you for confirming! Gonna close this issue here then - let's continue looking into it in the issue created for Emotion.

@joernroeder
Copy link
Author

thanks @Andarist for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants