aphrodite icon indicating copy to clipboard operation
aphrodite copied to clipboard

No support for siblings

Open iamrane opened this issue 8 years ago • 7 comments

Sometimes siblings are really important to looking at when styling custom checkboxes. For example this piece of code is quite common

[type=checkbox]:checked + .custom {
    ...
}

I find no way of replicating this in aphrodite. And I can't really come up with a work around without involving javascript.

iamrane avatar Aug 19 '16 11:08 iamrane

Oops, I thought I had responded to this! We don't currently support this, but it should be sorta solved by a similar solution as #10. We likely won't support the [type=checkbox] style of queries, because Aphrodite is meant more for component-level styling, so you would have to add a class name to each of your <button type="checkbox">s.

For now, you can use a JavaScript solution.

xymostech avatar Sep 02 '16 18:09 xymostech

I almost don't want to reply with this, because it's exploitative and should be patched out, but I'm finding it useful (so please don't patch it out!)...

You can use :nth-child(1n) + whatever to achieve most of what you're trying to get at... An example is my usage here:

export default Aphrodite.StyleSheet.create( {

    buttonGroup: {

        ':nth-child(1n) > *': {
            borderRadius: 0
        },

        ':nth-child(1n) > :first-child': {
            borderRadius: '8px 0 0 8px'
        },

        ':nth-child(1n) > :last-child': {
            borderRadius: '0 8px 8px 0'
        }
    }
} )

My suggestion to fix this in the library would be to allow child property names to start with a combinator, like >, +, ~, etc, though that might stray slightly from the main goal of Aphrodite.

ndugger avatar Sep 04 '16 22:09 ndugger

@ndugger Yeah, that's definitely a way to use + combinators currently, but it is a hack. KA uses the hack too, though, so we'll almost certainly provide a migration plan if/when we break it. :)

xymostech avatar Sep 06 '16 17:09 xymostech

Yeah, the major thing we need is similar to the opening example... We want to style checkbox labels differently depending on if the checkbox is checked or not:

  input[type=checkbox]:checked + label {
        background-color #FF0000;
  }

sontek avatar Oct 04 '16 08:10 sontek

@sontek you could accomplish this with the method I posted above:

Aphrodite.StyleSheet.create({

    checkbox: {
        ...

        ':checked + label': {
            ...
        }
    }
});

From what I can tell, Aphrodite isn't super smart when parsing; it just looks for a colon, and then accepts the full string.

ndugger avatar Oct 13 '16 13:10 ndugger

Any updates on supporting adjacent sibling selectors? It would be much appreciated.

sdras avatar Feb 09 '17 06:02 sdras

Any update on supporting child combinator as well? would be great!

axpence avatar Sep 08 '17 19:09 axpence