You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Compiled css and styled APIs treat both :hover and &:hover as targeting the same element (self), instead of a child element. In other words, a developer may write this without realising that both color and backgroundColor are actually targeting the same <div> element:
Perhaps we should change css and styled to forbid :hover, and only allow &:hover. Of course, this doesn't just affect :hover, but also every other CSS selector that exists.
Potential solutions:
Create ESLint rule to convert all ampersand-less selectors to ampersand-ful ones. Then require the ampersand-ful version &:hover through typing and runtime checks, in time for v1 release.
Recommended for consistency with CSS Nesting, Emotion(?), xcss and cssMap APIs, Sass, etc.
The above solution, but instead, converting all ampersand-ful selectors to ampersand-less ones.
Not sure if there are any pros to this
Unresolved problems:
What if a developer wants to use :hover for a child element?
Potential solution: discourage them from doing this in the first place (only allow styles to apply to the current element), or use *:hover as a workaround instead?
The text was updated successfully, but these errors were encountered:
ty @kylorhall-atlassian for bringing this up internally and for providing the examples.
With SCSS and the upcoming CSS Nesting module, there is a distinction made between:
:hover
(targeting a child element, like.class :hover
or.class *:hover
) and&:hover
(targeting the current element, like.class:hover
)Examples include SCSS and CSS Nesting module
The Compiled
css
andstyled
APIs treat both:hover
and&:hover
as targeting the same element (self), instead of a child element. In other words, a developer may write this without realising that bothcolor
andbackgroundColor
are actually targeting the same<div>
element:On the other hand,
cssMap
andxcss
only allow&:hover
, with:hover
not being valid according to the typescript types:compiled/packages/react/src/types.ts
Line 45 in 9857009
Perhaps we should change
css
andstyled
to forbid:hover
, and only allow&:hover
. Of course, this doesn't just affect:hover
, but also every other CSS selector that exists.Potential solutions:
&:hover
through typing and runtime checks, in time for v1 release.xcss
andcssMap
APIs, Sass, etc.Unresolved problems:
:hover
for a child element?*:hover
as a workaround instead?The text was updated successfully, but these errors were encountered: