Stories not applying the ::ng-deep classes from component .scss files
See original GitHub issueBug 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:
- Create an angular component that uses another component as a template.
- Override the original classes with
::ng-deep
in the .scss file. - Write a story using that component.
- Observe the
::ng-deep
classes are not loaded.
Please specify which version of Storybook and optionally any affected addons that you’re running
- @storybook/angular: 5.2.8
Screenshots
This is how it is supposed to look like and chrome dev tools
Vs how it is loading on storybook
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:
- Created 4 years ago
- Comments:9 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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!