igniteui-angular icon indicating copy to clipboard operation
igniteui-angular copied to clipboard

Question - headerClasses and cellClasses are not designed for scoped styles?

Open tkiryu opened this issue 8 years ago • 5 comments

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;
}

tkiryu avatar Apr 19 '18 11:04 tkiryu

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 avatar Apr 19 '18 15:04 simeonoff

@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 avatar Apr 23 '18 05:04 tkiryu

@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 avatar Apr 23 '18 07:04 simeonoff

@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.

tkiryu avatar Apr 24 '18 11:04 tkiryu

I am closing this issue as View Encapsulation and component themes have been covered in the documentation .

simeonoff avatar Nov 22 '18 17:11 simeonoff