Skip to content

Nested classes in @responsive directive getting prefixed #578

@oscaralexander

Description

@oscaralexander

I decided to start rewriting our (SASS) toolkit, starting off with my grid class. It's all BEM based, and I ran into the following unexpected/undesired behavior.

I have a SASS map named $grid-gaps that has key/values pairs (e.g. xs: 0.5rem). I loop over them to set the appropriate gap modifiers and wrap them in a @responsive directive so they become responsive:

.o-grid {
    ...

    @each $key, $val in $grid-gaps {
        @responsive {
            &--gap-#{$key} {
                margin: ($val * -0.5);

                .o-grid__col {
                    padding: ($val * 0.5);
                }
            }
        }
    }
}

However, the code above also creates responsive prefixes for the child classes, yielding the following:

.l\:o-grid--gap-xs {
    margin: -0.25rem;
}

.o-grid--gap-xs .l\:o-grid__col {
    padding: .25rem;
}

Instead of the output I desired/expected:

.l\:o-grid--gap-xs {
    margin: -0.25rem;
}

.l\:o-grid--gap-xs .o-grid__col {
    padding: .25rem;
}

I guess my understanding of @responsive isn't correct, but this felt like a bug to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions