Skip to content
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

Is it possible to disable chakra global styles? #232

Open
thenano opened this issue Dec 5, 2023 · 7 comments
Open

Is it possible to disable chakra global styles? #232

thenano opened this issue Dec 5, 2023 · 7 comments
Labels
bug Something isn't working chakra

Comments

@thenano
Copy link

thenano commented Dec 5, 2023

We use RSI in an app that uses MUI for the rest of it's styling. This seems to work almost fine, except there are some global chakra styles that leak when rendering RSI which in turn impact our app styles (thinks like body font size, and some spacing get's messed up).
I've seen that chakra has a "disableGlobalStyles" prop that can be passed to the provider which the documentation suggests would avoid this sort of leak, so I'm wondering if there's a way this can be done with RSI?
I have tried to wrap RSI with a ChakraProvider with the said prop but it didn't have any impact. I'm wondering if there's any other ways to do this that anyone would know of, or if we could pass props that could be set specifically in the provider?
Thanks very much!

@masiulis masiulis added the feature Improvement label Dec 5, 2023
@masiulis
Copy link
Contributor

masiulis commented Dec 5, 2023

Hey @thenano, thanks for bringing this up, we can expose this flag if it would be helpful. PRs are welcome!

@masiulis masiulis added the chakra label Dec 5, 2023
@thenano
Copy link
Author

thenano commented Dec 6, 2023

Thanks for the reply @masiulis! I had an initial hack at adding those flags to the provider and it didn't solve my problem, and also seemed to impact RSI styles negatively. I'll try and have a deeper look into it and report back.

@schembor
Copy link

@thenano Any luck on finding a way to disable the global styles? Otherwise, going to dive into myself and will post my findings

@thenano
Copy link
Author

thenano commented Dec 15, 2023

Hey @schembor I have managed to disable the global styles and cssRest by passing disableGlobalStyle: true, resetCss: false to both of the ChakraProvider s in the Providers component (not sure why there are 2 ChakraProvider).
This does fix the problem that I had, but it also messes up RSI styles which I think relies on some of the resets.
I did some further research and apparently it's possible to add an in place <CSSReset/> from chakra, but I haven't had a chance to test this out. Some discussion about it here: chakra-ui/chakra-ui#2802 (comment)
Thanks!

@masiulis masiulis added bug Something isn't working and removed feature Improvement labels Dec 18, 2023
@masiulis
Copy link
Contributor

masiulis commented Dec 18, 2023

Hey @schembor @thenano I didn't realise chakra was polluting global scope without a way to avoid it, that's pretty bad. We can definitely disable the global overrides and add our own.

From the comment:
1.) disableGlobalStyle - we do have table styles defined as global theme, so we cannot enable this flag. (We are planning to change table implementation in v5, but it doesn't fix the current problem)
2.) delete theme.styles.global - If we can do this before applying table styles, then we could delete just the defaults and keep the table styles. I have not checked what is in the default theme.styles.global though.
3.) resetCSS - this one should be enabled and we should copy https://github.com/chakra-ui/chakra-ui/blob/main/packages/components/css-reset/src/css-reset.tsx into our component with global styles fixed into this project until chakra fixes this.
4.) cssVarsRoot - this one should be added and we should use it in our forked code.

So what I think should be done is add resetCSS and cssVarsRoot, copy the /css-reset.tsx into this project, and fix the global styles. I can't promise when I would have time to do this, so PRs would be very much appreciated.

EDIT: previously discussed in #102

@doylio
Copy link

doylio commented Feb 20, 2024

Would love to see this change implemented!

FWIW conditionally rendering the import hides the worst of the damage. You can still see the style changing in the background when the modal opens however.

if (isOpen) {
  return <ReactSpreadsheetImport isOpen {...props} />

@fbricenho
Copy link

Would it make sense to use Web components for this? https://developer.mozilla.org/en-US/docs/Web/API/Web_components so the element is encapsulated and does not apply chakra ui to the whole DOM?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working chakra
Projects
None yet
Development

No branches or pull requests

5 participants