I have a dead simple CSS class that toggles opacity on <tr> elements with a basic ease transition:
tbody tr {
transition: opacity 1s ease;
}
tbody.blur tr {
opacity: .3;
}
tbody.blur tr.focus {
opacity: 1;
}
[ngClass] sets and removes the .blur and .focus classes. (The point is to blur all rows except one focused row.) The opacity works as expected, but the transition doesn't. If I type the classes directly into the tbody and tr tags with dev tools, the opacity transitions, but if the classes are set by ngClass, there's no transition.
I tried setting encapsulation: ViewEncapsulation.None, but that had no impact.
Am I missing something with transitions and ngClass?
Edit: ngClass code is basically
<tbody [ngClass]="{blur: focused > -1}">
<tr [ngClass]="{focus: focused === item.id}" *ngFor="let item of items">
The component class has a focused variable that is set to -1 on blur and to the respective id on focus.
Edit - solution
A computed getter that continually returns a new Array instance prevents the CSS transition; example here. If you return the same array instance, the transition occurs. The getter should return the same, mutable property of the class instance like this. Note that the property in the latter example is made up of other getters, which is fine.
[class.blur]="focused > -1"if the class name is fixed (and[class.focus]="focused === item.id"