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

Formatting styled component for nth-child() is wrong #5961

Closed
wooxudong opened this issue Mar 12, 2019 · 2 comments · Fixed by #9153
Closed

Formatting styled component for nth-child() is wrong #5961

wooxudong opened this issue Mar 12, 2019 · 2 comments · Fixed by #9153
Labels
lang:css/scss/less Issues affecting CSS, Less or SCSS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:tests Issues about tests that are not correct, should be added, or similar

Comments

@wooxudong
Copy link

Input:

const Steps = styled.div`
  @media (min-width: ${breakpoints.lg}) {
    ${Step} {
      margin-bottom: 90px;
    }

    ${Step}:nth-child(odd) {
      ${StepItemDescription} {
        grid-row: 1;
        grid-column: 3 / span 3;
      }
      ${Image} {
        grid-row: 1;
        grid-column: 7 / span 6;
      }
    }

    ${Step}:nth-child(even) {
      ${Image} {
        grid-row: 1;
        grid-column: 3 / span 6;
      }
      ${StepItemDescription} {
        grid-row: 1;
        grid-column: 10 / span 3;
      }
    }
  }
`;

Output:

const Steps = styled.div`
  @media (min-width: ${breakpoints.lg}) {
    ${Step} {
      margin-bottom: 90px;
    }

    ${Step}:nth-child (odd) {
      ${StepItemDescription} {
        grid-row: 1;
        grid-column: 3 / span 3;
      }
      ${Image} {
        grid-row: 1;
        grid-column: 7 / span 6;
      }
    }

    ${Step}:nth-child (even) {
      ${Image} {
        grid-row: 1;
        grid-column: 3 / span 6;
      }
      ${StepItemDescription} {
        grid-row: 1;
        grid-column: 10 / span 3;
      }
    }
  }
`;

Expected behavior:
Notice the space added between the nth-child (odd), this would not make the nth-child selector work. I am not sure how I can use prettier but still make this work.

@alexander-akait alexander-akait added type:bug Issues identifying ugly output, or a defect in the program lang:css/scss/less Issues affecting CSS, Less or SCSS labels Mar 12, 2019
@fisker
Copy link
Sponsor Member

fisker commented Nov 5, 2019

minimum reproduction

Prettier 1.18.2
Playground link

--parser babel

Input:

const Steps = styled.div`
  @media (min-width: 1px) {
    ${Step}:nth-child(odd) {}
  }
`;

Output:

const Steps = styled.div`
  @media (min-width: 1px) {
    ${Step}:nth-child (odd) {
    }
  }
`;

@thorn0
Copy link
Member

thorn0 commented May 12, 2020

Fixed by #7883. Needs tests.

@thorn0 thorn0 added type:tests Issues about tests that are not correct, should be added, or similar and removed type:bug Issues identifying ugly output, or a defect in the program labels May 12, 2020
@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Dec 7, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:css/scss/less Issues affecting CSS, Less or SCSS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:tests Issues about tests that are not correct, should be added, or similar
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants