question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stories not applying the ::ng-deep classes from component .scss files

See original GitHub issue

Bug or support request summary

When writing stories of an Angular component and having ::ng-deep classes in the .scss file with some !important, those styles are not loaded into storybook.

Steps to reproduce

To reproduce:

  1. Create an angular component that uses another component as a template.
  2. Override the original classes with ::ng-deep in the .scss file.
  3. Write a story using that component.
  4. Observe the ::ng-deep classes are not loaded.

Please specify which version of Storybook and optionally any affected addons that you’re running

Screenshots

This is how it is supposed to look like and chrome dev tools

image image

Vs how it is loading on storybook

image image

Code Snippets

The typescript file

@Component({
    selector: 'zip-select',
    providers: [
        {
          provide: NG_VALUE_ACCESSOR,
          useExisting: forwardRef(() => SelectComponent),
          multi: true
        }
    ],
    template: /* html */ `
    <mat-form-field appearance="outline">
        <mat-label>{{ label }}</mat-label>
        <mat-select [placeholder]=placeholder [zipDisableControl]=disabled disableOptionCentering [formControl]=formControl
            (selectionChange)="select($event)">
            <mat-option *ngFor="let item of items" [value]="item">
                {{ item }}
            </mat-option>
        </mat-select>
        <mat-error *ngIf="formControl.invalid" innerHTML="{{error}}" (click)="linkClick()">{{error}}</mat-error>
    </mat-form-field>
    `,
    styleUrls: ['./select.component.scss']
})

The scss file

::ng-deep .mat-select-panel {
    margin-top: 35px;
    padding-top: 8px !important;
    width: 100% !important;
}

::ng-deep .mat-option.mat-active {
    background-color: rgba(28, 112, 242, 0.1) !important;
}

::ng-deep .mat-form-field.mat-focused.mat-primary .mat-select-arrow {
    transform: rotate(225deg) !important;
    margin-top: 7px !important;
}

::ng-deep .mat-form-field .mat-select.mat-select-invalid .mat-select-arrow {
    color: #b00020 !important;
}
  
::ng-deep .mat-form-field .mat-select.mat-select-disabled .mat-select-arrow {
    color: #e8e8ec !important;
}

Any help is appreciated! Thank you

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
johnnysainzcommented, Feb 20, 2020

I’ve got the same issue. Trying to override mat-input styles with ::ng-deep. Works in the app, but not in storybook. Also tried no encapsulation without ::ng-deep. No change.

0reactions
stale[bot]commented, Apr 11, 2020

Hey there, it’s me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How and where to use ::ng-deep? - Stack Overflow
This will look anywhere in the component chain for .theme-dark and apply the css to the h1 if found. This is a good...
Read more >
How to Ditch ng-deep! | Angular Monthly Meetup - YouTube
ng-deep has been deprecated (for a very long time). If you architect your component styles correctly, you don't need to use ng-deep ever....
Read more >
Styling and CSS - Storybook
Storybook is a frontend workshop for building UI components and pages in isolation. Thousands of teams use it for UI development, testing, and...
Read more >
Angular:This is how I finally understood :host,:host ... - Medium
I am assuming that ChildBComponent has no CSS styles defined as of now. ... a CSS class applied or not to any ancestor...
Read more >
A guide to styling Angular Components | by John Au-Yeung
We can use CSS class names and selectors that make the most sense in each ... We can use /deep/ , >>> ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found