-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Emotion CSS overriding element styles in MDX Preview #10817
Comments
You either need to put your components inside a story, or you need to remove the docs styling: https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/recipes.md#overwriting-docs-container UPDATE: I think we might have already added the style reset to |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
I have been able to migrate the project to v6, but I am no longer able to view/use MDX currently, so I will keep you updated as things progress with #11094 |
@shilman I've got v6 working with Vue/MDX now and I can confirm that the Preview component styles are no longer overriding my typography styles. Thank you. |
Relieved to hear that. Yay! 🎉 |
It's not working for me. I use scss to apply my styles but even when I use |
Hi! I'm having the same issues as well as @gabor-ottlik-epam There is a generated class that is overriding bootstrap styles on my project. |
I have the same problem... |
@shilman it appears that the emotion styling classes like |
I ended up patching files of Storybook post install, i.e.:
|
@domyen I think you had a workaround for this? |
I'm having trouble with |
I think the problem here is that styles cascade. That's what they're supposed to do, but that presents some challenges. We need to apply styling to the Docs page while also rendering users stories inline (not in an iframe) – that means there may be style collisions as seen above. There are a few options with different tradeoffs but here are the most interesting ones:
|
@domyen I'm looking at the 3 options you've mentioned
|
I commented in another issue thread so I'll try to not repeat myself too much. @domyen's suggestion to "Make your CSS more specific than ours" is currently what we're having to do via As @domyen mentioned this is an issue with the cascade, which means the cascade should be fixed instead of increasing specificity. If Storybook controls where the emotion styles are inserted it'd be ideal if that was before the consumer's custom However, @njsokol's comment about the reset styles wouldn't be fixed from the cascade alterations because classes will still have a higher specificity than elements. We have this issue as well for something so small as a Essentially we want the headings & paragraphs to look like our brand's headings & paragraphs in a standard markdown/mdx rendering but it's proven difficult to have our styles respected. |
I was having the exact same problem - trying to apply utility classes to an I can happily and easily do the same thing within a regular old <style type="text/css">{ /* Tailwind CSS */ }</style>
<style type="text/css">{ /* Styles specific to a loaded component like a button */ }</style> I assumed I'd be able to do the same with <style type="text/css">{ /* Tailwind CSS */ }</style>
<style type="text/css">{ /* Previously loaded styles specific to previously loaded components */ }</style>
<style data-emotion="css" data-s="">{ /* Generated sbdocs snippet */}</style>
<style data-emotion="css" data-s="">{ /* Generated sbdocs snippet */}</style>
<style data-emotion="css" data-s="">{ /* Generated sbdocs snippet */}</style>
<style data-emotion="css" data-s="">{ /* Generated sbdocs snippet */}</style> Because the sbdocs styles are so specific, for example every single I haven't yet seen a valid reason for this behaviour to be intentional - and I believe it could be "fixed" by re-ordering the sbdocs CSS to come before (almost?) everything else, rather than after it. I've come up with a horrific workaround which proves that re-ordering works (at least, for me). It keeps the sbdocs styles in the export const FixMdxStyles = () => {
const nonDocsStyles = [...document.querySelectorAll('style:not([data-emotion])')];
nonDocsStyles.reverse().forEach(styles => document.body.prepend(styles));
} I'm using that snippet just at the bottom of a couple of documentation |
Having the same issue with fonts and styles in MDX files overriding global/app defined styles. @burntcustard that doesn't seem to work for me. |
My fixWrap all components in class import ...
<Meta of={BannerStories} />
<div className="sb-unstyled">
# h1
...
</div> |
Describe the bug
I am working on a documentation-only
.mdx
file for our design system's typography styles. I have the following block in my file:These
type-
styles in my CSS are only used to adjust the font size, but they are getting multiple other styles applied that seem to be getting injected as part of Storybook's processing of the content. I have also tried swapping the<div>
to be a<Story>
tag, but it made no difference.Expected behavior
Storybook should not be injecting it's styling into any
Preview
block.Screenshots
System:
Environment Info:
System:
OS: macOS Mojave 10.14.6
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Binaries:
Node: 10.17.0 - /usr/local/opt/node@10/bin/node
Yarn: 1.22.4 - ~/.yarn/bin/yarn
npm: 6.11.3 - /usr/local/opt/node@10/bin/npm
Browsers:
Chrome: 81.0.4044.138
Firefox: 75.0
Safari: 13.1
The text was updated successfully, but these errors were encountered: