Question - headerClasses and cellClasses are not designed for scoped styles?
Description
Please take a look at a sample https://stackblitz.com/edit/igx-grid-cell-style.
In this sample, background colors of header and cell on "string1" column are not changed, whereas, those on "string2" and "string3" columns are changed.
Unfortunately, headerClasses and cellClasses don't apply scoped style.
Do we have no choice but using ng-deeped styles or global styles? If you have any good ideas on this, please let me know.
For "string1"
// app.component.html
<igx-column [field]="'stringColumn'" [dataType]="'string'" [header]="'string1'" [headerClasses]="'header1'" [cellClasses]="'cell1'">
// app.component.scss
// These style is applied only for this component.
.header1 {
background-color: red;
}
.cell1 {
background-color: red;
}
For "string2"
// app.component.html
<igx-column [field]="'stringColumn'" [dataType]="'string'" [header]="'string2'" [headerClasses]="'header2'" [cellClasses]="'cell2'">
// app.component.scss
// These styles are down through the child component tree into all the child component.
:host::ng-deep {
.header2 {
background-color: red;
}
.cell2 {
background-color: red;
}
}
For "string3"
// app.component.html
<igx-column [field]="'stringColumn'" [dataType]="'string'" [header]="'string3'" [headerClasses]="'header3'" [cellClasses]="'cell3'">
// styles.scss
// These styles are global.
.header3 {
background-color: green;
}
.cell3 {
background-color: green;
}
Penetrating encapsulated styles in the emulated view encapsulation is done by using ::ng-deep. This is angular related and not an issue of Ignite UI.
@simeonoff thank you for your comment.
I don't think this is a bug of Ignite UI, either. I just wanted to know whether there is a better way to style it without ::ng-deep or global style.
By the way, I guess almost all the people would do the first approach and make a mistake as I did.
There are other properties that require ::ng-deep like evenRowCSS, oddRowCSS and so on.
So, could you clarify this on the document?
@tkiryu I will be including a section in the theming documentation (when I have time, preferably soon) that specifically talks about view encapsulation. I feel this topic is often neglected by developers, hence why they stumble when it comes to styling view encapsulated elements.
I am leaving this issue open for now, for further discussion and reference.
@simeonoff thank you so much!
I feel this topic is often neglected by developers, hence why they stumble when it comes to styling view encapsulated elements.
Yeah, I think so. We should more care about view encapsulation when we style components.
I am closing this issue as View Encapsulation and component themes have been covered in the documentation .