question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFC: Component Selector

See original GitHub issue

I was chatting to @markdalgleish at Reactive conf and he had this great idea to implement a other-styled-component-selector.

The API would look like this:

const Button = styled.button`some: styles;`

const Box = styled.box`
  > ${Button} {
    // A button component nested within a box will have these styles
    other: styles;
  }
`

This would allow you to override styles of children, and from children react to parents, too! What do you think?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:70
  • Comments:25 (12 by maintainers)

github_iconTop GitHub Comments

19reactions
mxstbrcommented, Jan 31, 2017

I am not convinced that styling children from the parent is something to encourage.

It’s not something we will encourage, but that doesn’t mean the possibility shouldn’t be there. The same thing applies to nesting, I try to avoid nesting as much as possible and we could’ve made it impossible in styled-components, but it does have it fringe use cases and we want to cover all the ground.

17reactions
wmertenscommented, Jan 31, 2017

I am not convinced that styling children from the parent is something to encourage.

In any case, when it is unavoidable, like when you are making a layout component based on flexbox, I do something like

const Layout = styled.div`
  display: flex;
  & > * {
    flex: 1;
  }
`

The child selectors are also very useful for these purposes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS Definition for a LWC Component - RFCs
Implementations should not rely on or use the selectors generated by the Lightning Web Components compiler. This is an implementation detail of Lightning...
Read more >
RFC 7408: Forwarding and Control Element Separation ...
Code Components extracted from this document must include Simplified BSD ... <xsd:key name="structComponentID1"> <xsd:selector xpath="lfb:component"/> ...
Read more >
React RFC: Context Selectors : r/reactjs - Reddit
I'm building react-complex-tree, an unopinionated tree component for react, and recently released a new version! media poster.
Read more >
Selectors Level 4 - W3C
Selectors have been optimized for use with HTML and XML, and are designed to be usable in performance-critical code. They are a core...
Read more >
RFC 5474 - A Framework for Packet Selection and Reporting
A Framework for Packet Selection and Reporting (RFC 5474, March 2009. ... This framework details the components of this architecture, then describes some ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found