There is no federal law that prevents employer discrimination based on political beliefs. There are some states, specifically California in this case, that prevent employers from discrimination based on political activities and/or affiliations. However, most states prevent employers from controlling political activities outside of work
The First Amendment does not apply to private institutions, only public ones. Private institutions can outright ban political discussion with no repercussions and cannot be liable for termination on the grounds of political beliefs expressed within the workplace sans some states.
So while it isn't "illegal", it can be restricted within private companies.
However, most private companies don't allow political discussion and it's not illegal to control this unless you live in certain states, California being one of them.
Explanation in detail here: https://www.nolo.com/legal-encyclopedia/can-employers-discri...