question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't change background of canvas

See original GitHub issue

Describe the bug I can’t change the background of the canvas. Also looking at the tutorials the canvas should have white background but for some reason mine is grey.

To Reproduce Clone repo at: https://github.com/jauggy/storybook-background-issues

npm i

npm run storybook

Notice the Canvas background is gray. Also when clicking the background addons you can’t change it.

Expected behavior White background on canvas and ability to change the canvas background via the background addon.

Screenshots If applicable, add screenshots to help explain your problem. image

Code snippets If applicable, add code samples to help explain your problem.

System:

Environment Info:

  System:
    OS: Windows 10 10.0.19041
    CPU: (4) x64 Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz
  Binaries:
    Node: 12.18.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 84.0.4147.135
    Edge: Spartan (44.19041.423.0), Chromium (85.0.564.41)
  npmPackages:
    @storybook/addon-essentials: ^6.0.20 => 6.0.20
    @storybook/react: ^6.0.20 => 6.0.20

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
yannbfcommented, Oct 15, 2020

Hey @jauggy thanks a lot for putting up a reproduction! It helps a lot. The reason the addon does not work is that the lib you’re using, CoreUI, sets a default background color at the body level. This is the line of code that gives the side effect:

@import "~@coreui/coreui/scss/coreui"

In storybook 6.0, the background is set at the iframe level, which is less specific than the body. In Storybook 6.1 this problem is fixed. This is your storybook running with ^6.1.0-alpha.23: Kapture 2020-10-15 at 12 00 01

Also, Storybook 6 supports typescript out of the box! So you can remove these lines from your main.js:

webpackFinal: async (config) => {
    config.module.rules.push({
      test: /\.scss$/,
      use: ["style-loader", "css-loader", "sass-loader"],
      include: path.resolve(__dirname, "../"),
    });

-    config.module.rules.push({
-      test: /\.(ts|tsx)$/,
-      loader: require.resolve("babel-loader"),
-      options: {
-        presets: [["react-app", { flow: false, typescript: true }]],
-      },
-    });
-    config.resolve.extensions.push(".ts", ".tsx");

    return config;
},

You can also use main.ts and preview.(ts|tsx)!

1reaction
petomicommented, Nov 20, 2020

I had the same issue in 6.0.5 (docs Canvas elements not using the same background-color that they do in the sandbox mode) but this issue appears to be solved by updating to Storybook 6.1.1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why can't I change the background of my canvas?
You need to specify the background colour in the style attribute, like this: style="border:4px solid black; background-color: yellow".
Read more >
Why Power BI Canvas Background Color is not Changing
Power BI tutorial for beginners to understand why the canvas background color doesn't change even after changing the color and what setting ...
Read more >
Why Power BI Canvas Background Color is not Changing
Power BI tutorial for beginners to understand how to make settings in power bi canvas to make sure background color changes.
Read more >
Solved: Canvas extension color for the background cannot c...
Press X to switch foreground/background. The standard way to set a background color is to click the background swatch in the toolbar.
Read more >
Solved: Background Color - Instructure Community
Is there a way to change the background color on a page? I have tried HTML code & it doesn't work. Solved! Go...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found