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

Link component not getting styled by <style jsx> #610

Closed
tmayr opened this issue Jan 2, 2017 · 6 comments
Closed

Link component not getting styled by <style jsx> #610

tmayr opened this issue Jan 2, 2017 · 6 comments

Comments

@tmayr
Copy link

tmayr commented Jan 2, 2017

When using scoped <style jsx> and having a <Link> element, the produced <a> don't get any style.

I do believe however, this is intentional, as the scope will only bind to that specific component it was declared from, however, it seems a bit confusing trying to use and style <Link> from the parent component and getting this result.

Is there any way to keep the scope, and style just <Link> childrens?
Or maybe a way to force/include the style leakage to NextJS components/helpers?

Source:
Version: 2.0.0 Beta 12
https://nextjs-unstyled-link-exgwwtxueh.now.sh
https://nextjs-unstyled-link-exgwwtxueh.now.sh/_src/?f=pages%2Findex.js

@arunoda
Copy link
Contributor

arunoda commented Jan 2, 2017

I hope this is related to this: #272
You need to provide a child <a/> component inside the `

Then you can style that <a/> tag as you want.

@tmayr
Copy link
Author

tmayr commented Jan 2, 2017

Yeah, using an <a/> inside <Link> works but...

Even if #272 passes, if you don't provide a children, the same behavior will occur.

Seems pretty counter intuitive to stick your <a> in there, when <Link> actually provides one too if you don't specify any element, and you can't add an href to the child anchor, otherwise, it'll break <Link as>. (Not supporting className is also quite odd)

@rauchg
Copy link
Member

rauchg commented Jan 2, 2017

It's by design that elements that are not statically present don't get styles. The goal is to avoid implicit side-effect styles, which is the main issue with CSS in my opinion.

You can still access the element through "global selectors" by using something like:

p > :global(a) {
  color: red;
}

But that's just a escape-hatch. I think it's always best to pass an element to <Link>. Recently I've actually started advocating for the idea of not supporting automagically creating an element, in fact.

@tmayr
Copy link
Author

tmayr commented Jan 2, 2017 via email

@rauchg
Copy link
Member

rauchg commented Jan 2, 2017

Yep @tmayr. Thanks for your feedback, I think we can start displaying a warning and eventually deprecate it.

@rauchg rauchg closed this as completed Jan 2, 2017
@tmayr
Copy link
Author

tmayr commented Jan 2, 2017 via email

@lock lock bot locked as resolved and limited conversation to collaborators May 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants