Only assign className if changed for #14250

This aids performance in some browsers (where adding/removing a
class which is already present triggers a CSS render anyway).