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

:has(:focus-visible) gives different and unexpected results to &:has(:focus-visible) #1598

Open
dddlr opened this issue Dec 18, 2023 · 0 comments
Labels
bug 🐛 Something isn't working

Comments

@dddlr
Copy link
Collaborator

dddlr commented Dec 18, 2023

Describe the bug
We expect the :focus-visible in the :has(:focus-visible) selector to be unmodified in the output CSS, just like in &:has(:focus-visible) (with the ampersand). However, this is not the case - for some reason, the presence of & matters in this specific example when it in fact should not.

To Reproduce

Container gives correct output, while Container2 gives incorrect output. We want Container2 to give the same output as Container.

const Container = styled.div({
  "&:has(:focus-visible)": {
    "background": "purple",
  },
});
// results in
// ._1o9o1cnh:has(:focus-visible) { background-color: purple }
// (correct!)

const Container2 = styled.div({
  ":has(:focus-visible)": {
    "background": "purple",
  },
});
// results in
// ._1vux1cnh:has(._1vux1cnh:focus-visible) { background-color: purple }
// (wrong!)

const App = () => (
  <>
    <Container>
      {"Hello from webpack?"}
      <input name="firstName" type="text" />
      {"Goodbye from webpack!"}
    </Container>
    <Container2>
      {"Hello from webpack?"}
      <input name="firstName" type="text" />
      {"Goodbye from webpack!"}
    </Container2>
  </>
);

Screenshots
The above code example, with :focus-visible turned on for both <input> elements through the Chrome inspection tools:

Screenshot 2023-12-18 at 18 14 28
@dddlr dddlr added the bug 🐛 Something isn't working label Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant