Notify events when style class changes

I’d like child elements to know when their parents’ style class changes with something like an AddToClassListEvent and RemoveFromClassListEvent.

My use case is easily highlighting child elements when a parent element is selected in a ListView. I might be misunderstanding what the existing events do, so please let me know if there’s a better way to workaround this.

You should do this via USS, like so:

.parentClassName--selected > .childClassName {
    color: blue;
}

You can use the Debugger to see what classes and pseudo states (ie. hover, active…) are on the parent element while it is selected and just add “> .youChildClassName” at the end to create your new selector.

Note, it’s best to use the “>” operator if you can, which requires exact parent/child relationship. If you just use a " " space, the child can be a grandchild, or grand-grandchild, etc. But this is expansive to resolve because all combinations have to be checked.

1 Like

Wow!! awesome!!! I had a feeling I was doing something wrong.