Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

theming: parsing a registered style with Media Queries or keyframes produces incorrect rules #9869

Closed

Description

@natete

Actual Behavior:

  • What is the issue? * When a CSS stylesheet containing media queries (or keyframes or anything that can have nesting) is registered using the Theming Provider, Angular Material processes it in a wrong way causing an incorrect result.

Now the string representing the CSS is split using a regex that doesn't take into account nesting, causing nested rules to be considered independent rules. For example:

@media (min-width: 0) and (max-width: 700px) {

  .md-THEME_NAME-theme .test-background {     
    background-color: pink;
  }

  .md-THEME_NAME-theme p {
    color: blue;
    font-weight: bold;
  }
}

Will be parsed:

@media (min-width: 0) and (max-width: 700px) {

  .md-test-theme .test-background {     
    background-color: pink;
  }
}

.md-test-theme p {
  color: blue;
  font-weight: bold;
}

Causing a bad behavior because styles defined to p elements will be applied regardless the screen size.

  • What is the expected behavior? Parsing a CSS should take into account nesting. In the example the correct result would be:
@media (min-width: 0) and (max-width: 700px) {

  .md-test-theme .test-background {     
    background-color: pink;
  }

  .md-test-theme p {
    color: blue;
    font-weight: bold;
  }
}

CodePen (or steps to reproduce the issue): *

  • CodePen Demo which shows your issue: http://codepen.io/natete/pen/BLGPbd
  • Details: Second rule inside the media query is extracted from it causing the rules to be applied in a wrong manner.

Angular Versions: *

  • Angular Version: 1.5.8
  • Angular Material Version: 1.1.1

Additional Information:

  • Browser Type: * all
  • Browser Version: * all
  • OS: * all
  • Stack Traces:

Shortcut to create a new CodePen Demo.
Note: * indicates required information. Without this information, your issue may be auto-closed.

Do not modify the titles or questions. Simply add your responses to the ends of the questions.
Add more lines if needed.

Activity

  1. added 2 commits that reference this issue on Oct 20, 2016
    91e8fc4
    4f92c65
  2. added this to the 1.1.2 milestone on Oct 20, 2016
  3. added 5 commits that reference this issue on Oct 24, 2016
    3773900
    a7f055c
    f190436
    40dae3e
    f173fba
  4. 43 remaining items

  5. modified the milestones: 1.1.21, 1.1.22 on Aug 15, 2019
  6. modified the milestones: 1.1.22, 1.1.23 on Oct 22, 2019
  7. modified the milestones: 1.1.23, 1.2.0 on Jun 8, 2020
  8. modified the milestones: 1.2.0, 1.2.1 on Jul 29, 2020
  9. modified the milestones: 1.2.1, 1.2.2 on Sep 14, 2020
  10. Splaktar commented on Dec 6, 2020

    @Splaktar
    Contributor

    Some details on the given CodePen and this reproduction:

    • You have to reproduce this on a small display (700px wide or smaller)
    • You see white text instead of blue because the CSS rule is rendered as
    .md-test-theme * {
        color: blue;
        font-weight: bold;
        font-size: 6px;
    }

    Instead of

    @media (max-width: 700px) and (min-width: 0) .md-test-theme * {
        color: blue;
        font-weight: bold;
        font-size: 6px;
    }

    Broken

    Screen Shot 2020-12-05 at 21 06 08

    It should render this way

    Screen Shot 2020-12-05 at 21 05 44

  11. added a commit that references this issue on Dec 6, 2020
    a784ede
  12. added a commit that references this issue on Dec 9, 2020
    71dc4eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions