Skip to content

Commit 58be979

Browse files
author
Nedyalko Nikolov
authored
Merge pull request NativeScript#2324 from NativeScript/nnikolov/CssCascadeSelectorsIssue
Fixed issue NativeScript#1655 cascading css selectors.
2 parents 1970c8b + 7fbfc92 commit 58be979

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

tests/app/ui/styling/style-tests.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,23 @@ export function test_UsingSameSelectorsWithSpecific_ShouldApplyLatest() {
14261426
}
14271427
helper.buildUIAndRunTest(testButton, testFunc, testCss);
14281428
}
1429+
1430+
export function test_CascadingClassNamesAppliesAfterPageLoad() {
1431+
const stack = new stackModule.StackLayout();
1432+
const label = new labelModule.Label();
1433+
label.text = "Some text";
1434+
label.cssClass = 'lab1';
1435+
stack.addChild(label);
1436+
1437+
application.addCss(".added { background-color: red; } .added .lab1 { background-color: blue; } .lab1 { color: red}");
1438+
1439+
helper.buildUIAndRunTest(stack, function (views: Array<viewModule.View>) {
1440+
helper.assertViewColor(label, "#FF0000");
1441+
stack.className = "added";
1442+
helper.assertViewBackgroundColor(label, "#0000FF");
1443+
helper.assertViewBackgroundColor(stack, "#FF0000");
1444+
});
1445+
}
14291446
// <snippet module="ui/styling" title="styling">
14301447
// For information and example how to use style properties please refer to special [**Styling**](../../../styling.md) topic.
14311448
// </snippet>

tns-core-modules/ui/core/view-common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,10 @@ export class View extends ProxyObject implements definition.View {
614614
if (metadata.affectsStyle) {
615615
this.style._resetCssValues();
616616
this._applyStyleFromScope();
617+
this._eachChildView((v) => {
618+
v._checkMetadataOnPropertyChanged(metadata);
619+
return true;
620+
});
617621
}
618622
}
619623

0 commit comments

Comments
 (0)