-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Widget styles override consuming app styles #144
Comments
Solution for React: To avoid using global styles in the widgets, we need to prevent or limit the application of the global CSS rules that EuiProvider and Emotion's CSS-in-JS solution inject into the document. We can do this by using a CacheProvider as described here: emotion-js/emotion#1078
This works well with React but not with the plainJS environment so the issue is still open. |
More hints:
|
@jusa3 Are these issues still present in the latest version of elasticUI? The migration to emotion seems to be complete and since v96 https://github.com/elastic/eui/releases/v96.0.0 all css files are removed. Combined with the https://emotion.sh/docs/@emotion/cache#options and https://eui.elastic.co/v97.3.1/#/utilities/provider#theming-and-global-styles I would assume that the styling of elasticui does not interfere with other style definitions. If it does, we should open an issue with elasticui and try to resolve the problem. If you plan to migrate away from elasticUI, please discuss this change with any downstream users of the widgets, as there are some implications. |
Regardless of the UI kit used, this problem will occur. Since each application has its own design language, it will most likely at some point conflict with the one used in a reused component. Therefore, as a user of a library, you can either accept the difference, if it is not so big that it affects the usability, or you have to adapt it to your liking. The latter requires a library that allows this kind of customisation and thus is bit more complex to create. |
Widget styles override consuming app styles. Remove the EuiProvider that injects the problematic global styles and introduce a css object to the EUI components with custom styles. Related to #144
Add custom css objects to the DataContentWidget to get the original style. Related to #144
Two more approaches:
https://github.com/ts4nfdi/terminology-service-suite/tree/fix/prevent%23-global-style-injection
https://github.com/ts4nfdi/terminology-service-suite/tree/eui-style-issue Code example:
|
Next approach (WIP): address the problem separately for React and html widgets. Using the custom cache (as described above) for React and a Shadow DOM for html: https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM |
Using a custom cache alone does not solve the issue. The styles are still applied globally to all matching DOM elements in the app (the Eui global styles are injected into the <style> tag in the of the document). Eui applies several global styles, including resets, to standard HTML elements like body, html, button, and more. It seems that the Emotion cache manages style injection order, but it doesn’t encapsulate styles to apply only within specific parts of the DOM. |
We tested the Shadow DOM approach like this:
and in the consumin app:
But even without injecting the eui theming styles, the eui component styles were missing and the global styles were still injected globally. No DOM support: elastic/eui#7158: |
Perhaps the EUI team has an idea on how to solve this problem: elastic/eui#8203 |
add css classes to restore the autocomplete widget style when the global style option of the EuiProvider is removed. As a proof of concept that this approach might work for all widgets. related to #144
Problem: The style issue stems from the global styles being injected by the EuiProvider from @elastic/eui and the Emotion CSS-in-JS library that it uses for theming and styling.
Temporary workaround: After the widget is rendered, remove the injected global styles. Specifically, the
<style data-emotion="css-global" data-s=""></style>
tag is dynamically generated by Emotion when global styles are applied, and it seems to override the app's existing styles, causing unintended changes. This happens because EuiProvider applies its own global styles which may conflict with or override the app’s styles. When we remove the style tag from the DOM, those global styles no longer apply.The text was updated successfully, but these errors were encountered: