Emotion: Using Pseudo selectors in object

Created on 19 Mar 2018  路  2Comments  路  Source: emotion-js/emotion

  • emotion version: "^8.0.10"
  • react version: "^16.2.0"

Relevant code.

const RadioButton = styled('div')({
display: 'inline-flex',
justifyContent: 'center',
alignItems: 'center',
flex: '0 0 auto',
width: 20,
height: 20,
borderRadius: '50%',

'&::after': {
display: 'block',
content: ''
}
});

3


What you did:

I used &::after using object but the after pseudo does not add in the css.
but when I tried to use it as string it is ok.

Here is the screenshot for object and string
OBJECT

1

STRING

2

Suggested solution:

added helper for after pseudo to retain object for the whole project.

index.js

import { after } from './helpers'
const RadioButton = styled('div')(
{
display: 'inline-flex',
justifyContent: 'center',
alignItems: 'center',
flex: '0 0 auto',
width: 20,
height: 20,
borderRadius: '50%'
},
after({
display: 'block',
width: 12,
height: 12,
borderRadius: '50%'
})
);
3

helpers.js
4

WHAT I OBSERVED
Using this line of codes, i put content in the object, also in the string

5

the output in CSS is this:

6

There is a px on the content that came from the object

Most helpful comment

content: "''" should work.

All 2 comments

content: "''" should work.

@tkh44 think it'd be possible to do a PR to improve that behavior? I might have some interest in doing so.

Basically any content passed to those pseudo selectors (::before and ::after) requires the value to be stringified.

Here's a CodeSandbox demonstrating the "issue" (if it's even that!).

Was this page helpful?
0 / 5 - 0 ratings