I am facing a challenge with a React component that is being embedded in various webpages, either through an extension or as a third-party tool.
Most of the styling for this component is done using JSS, ensuring unique class names that cannot be overridden by the host page.
However, certain elements within our component, such as <p>
, <button>
, and headings like <h1>
and <h2>
, are standard for accessibility purposes. Unfortunately, these elements' styles can get overwritten by the hosting page if it uses specific selectors targeting these elements.
I attempted to encapsulate the React component within a Shadow DOM, but encountered difficulties. It seemed to interfere with React's functionality, resulting in issues like click events not being passed correctly. Even tools like react-shadow
(https://github.com/Wildhoney/ReactShadow) did not provide a solution.
Is there a method to safeguard these essential elements' styles from external overrides?