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.

Addon-knobs not working unless applied directly in story props

See original GitHub issue

Describe the bug Hard to describe, but the knobs are not working unless the options are directly defined in the props of the story. I normally define a props variable I can share between stories for common data. If I put any knob options in this props variable it will not display in the knobs tab in Storybook. Occasionally if I refresh the page I can see both select knobs, but if I change the width one it will just disappear completely. The widthThatWorks has no issue and does update in Storybook properly.

To Reproduce Run the story file code below.

Expected behavior The code below should display two select knob options. Occasionally displays both, but only one ever works.

Screenshots Here’s how it looks when they both finally display. Screenshot from 2019-06-27 08-26-40

What it looks like if you make a change to width. Screenshot from 2019-06-27 08-21-04

Code snippets

import { select, withKnobs } from '@storybook/addon-knobs';
import { moduleMetadata, storiesOf } from '@storybook/angular';

const props = {
  width: select('width', ['full', 'auto', 200, 320, 400, 600], 320)
};

storiesOf('Knob Test', module)
  .addDecorator(
    moduleMetadata({
      imports: []
    })
  )
  .addDecorator(withKnobs)
  .add('Basic', () => ({
    template: `
      width: {{ width }}<br>
      widthThatWorks: {{ widthThatWorks }}
    `,
    props: {
      ...props,
      widthThatWorks: select('widthThatWorks', ['full', 'auto', 200, 320, 400, 600], 320)
    }
  }));

System:

  • OS: Linux Ubuntu 18.04
  • Device: [e.g. iPhoneX, Macbook Pro 2018]
  • Browser: Chromium 75, Firefox 67
  • Framework: Angular
  • Addons: Knobs
  • Version: 5.1.8

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
shilmancommented, Sep 8, 2019

@matthewmorek Updated the title.

TBH, knobs is legacy code at this point and in need of a major cleanup. We’re hoping to rearchitect it for 6.0 to address these issues and more.

1reaction
ralph-devcommented, Nov 2, 2020

@nunoleong

import React from "react";
import { storiesOf } from "@storybook/react-native";
import { CardColorSquare, ICardColorSquare } from "./index";
import { select, text } from "@storybook/addon-knobs";

type TCardColorSquareArgs = (
  color?: string,
  groupID?: string,
) => ICardColorSquare;

export const CardColorSquareArgs: TCardColorSquareArgs = (
  color = 'pink',
  groupID= 'CardColorSquareArgs'
) => {
  return {
    color: select('color',['blue','red'], 'red', groupID),
  }
}

storiesOf("CardColorSquare", module).add("Basic", () => (
  <CardColorSquare {...CardColorSquareArgs()} />
  ));

Works fine for me!

Read more comments on GitHub >

github_iconTop Results From Across the Web

react storybook addon knobs not showing - Stack Overflow
I was able to fix this simply by hitting the D key, which changes the addon panel orientation. (You can also do this...
Read more >
@storybook/addon-controls - npm
After installing the controls addon, you'll see a new tab that shows the component's props, but it doesn't show controls because the story...
Read more >
Display the JSX of a React Storybook Story with the JSX Addon
Anyone else having issues with the JSX addon? For me it doesn't display what I am expecting, i.e. the JSX with props used....
Read more >
storybook/addon-knobs/README.md - UNPKG
3, Storybook Addon Knobs allow you to edit React props dynamically using ... 120, // "withKnobs" decorator should be applied before the stories...
Read more >
Storybook Docs with mdx support and addon knobs - Medium
Okay, not bad, everything seems to be working after that. ... If embedding the story directly into a mdx file, the source won't...
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