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

Controls: boolean control throws a red warning #10967

Open
matheo opened this issue May 28, 2020 · 23 comments
Open

Controls: boolean control throws a red warning #10967

matheo opened this issue May 28, 2020 · 23 comments

Comments

@matheo
Copy link
Member

matheo commented May 28, 2020

Describe the bug

Playing with "@storybook/addon-controls": "6.0.0-beta.17" I got this warning after clicking a boolean control, which is the inverseColors input (at the beggining of the screenshot):

image

Upcoming clicks in the checkbox doesn't throw this,
as it seems that the checkbox is already changed to controlled.

System:

Environment Info:

  System:
    OS: Linux 5.4 Ubuntu 20.04 LTS (Focal Fossa)
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 10.18.0 - ~/.nvm/versions/node/v10.18.0/bin/node
    Yarn: 1.22.4 - /usr/bin/yarn
    npm: 6.14.2 - ~/.nvm/versions/node/v10.18.0/bin/npm
  Browsers:
    Chrome: 83.0.4103.61
    Firefox: 76.0.1
  npmPackages:
    @storybook/addon-a11y: 6.0.0-beta.17 => 6.0.0-beta.17 
    @storybook/addon-actions: 6.0.0-beta.17 => 6.0.0-beta.17 
    @storybook/addon-controls: 6.0.0-beta.17 => 6.0.0-beta.17 
    @storybook/addon-docs: 6.0.0-beta.17 => 6.0.0-beta.17 
    @storybook/addon-links: 6.0.0-beta.17 => 6.0.0-beta.17 
    @storybook/addon-viewport: 6.0.0-beta.17 => 6.0.0-beta.17 
    @storybook/addons: 6.0.0-beta.17 => 6.0.0-beta.17 
    @storybook/angular: 6.0.0-beta.17 => 6.0.0-beta.17 
    @storybook/cli: 6.0.0-beta.17 => 6.0.0-beta.17 
    @storybook/source-loader: 6.0.0-beta.17 => 6.0.0-beta.17
@matheo
Copy link
Member Author

matheo commented May 29, 2020

The same happened with a number control:

image

@shilman shilman self-assigned this May 29, 2020
@shilman
Copy link
Member

shilman commented Jun 7, 2020

Do you have a public repro for this, or can you add one to official-storybook? I played around with this for a minute in next (beta.22) and couldn't repro in https://raw.githubusercontent.com/storybookjs/storybook/next/examples/official-storybook/stories/addon-docs/props.stories.mdx

@matheo
Copy link
Member Author

matheo commented Jun 7, 2020

@shilman wooops,
I forked the ControlsPanel with the exact same code and registered a panel just like @storybook/addon-controls. I thought it should behave the same as the official plugin, but it doesn't then :(

@shilman
Copy link
Member

shilman commented Jun 7, 2020

@matheo hmmm did you try recently? might have gotten fixed since you filed this through some other change, since i've been messing with this code a bunch

@matheo
Copy link
Member Author

matheo commented Jun 7, 2020

yeah, I just compared the code of addon-controls and my fork, and they are basically the same.

I will dig a little bit in the argTypes of the controls that are failing to see if there's something missing there.

@shilman
Copy link
Member

shilman commented Jun 8, 2020

Thanks! It wouldn't surprise me if there was still a bug, just having trouble repro-ing it! 😄

@shilman
Copy link
Member

shilman commented Jun 9, 2020

@matheo I found a repro case in examples/angular-cli, so I don't need one anymore. Fix coming soon!

@matheo
Copy link
Member Author

matheo commented Jun 9, 2020

I checked some stories of angular-cli and there was no error thrown, so I got surprised :P

@stale
Copy link

stale bot commented Jul 3, 2020

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!

@shilman
Copy link
Member

shilman commented Aug 31, 2020

ZOMG!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.21 containing PR #12322 that references this issue. Upgrade today to try it out!

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Aug 31, 2020
@gregfagan
Copy link

I updated to v6.0.21 and this is still happening for me.

@shilman
Copy link
Member

shilman commented Aug 31, 2020

@gregfagan Do you have a repro repo you can share?

@gregfagan
Copy link

@gregfagan Do you have a repro repo you can share?

Sorry, not at the moment; this is in a private repo

@gregfagan
Copy link

Actually this might have been a stale cache or some other problem. It is no longer throwing errors for my. My mistake.

@monolithed
Copy link

The same problem with 6.1.0-rc.0.

...
        rotate: {
            description: 'Повернуть элемент (не работает в IE 9)',
            table: {
                type: {
                    summary: 'number'
                },
                defaultValue: {
                    summary: 0
                }
            },
            control: {
                type: 'number'
            }
        },
...

Снимок экрана 2020-11-13 в 0 23 23

@shilman
Copy link
Member

shilman commented Nov 13, 2020

@monolithed does it fix it to add:

        rotate: {
            description: 'Повернуть элемент (не работает в IE 9)',
            defaultValue: 0,
            table: { ... },
            control: { ... },
        }

@monolithed
Copy link

monolithed commented Nov 13, 2020

@shilman, I have already tried it before. it can be reproduced with the simplest component:

const Input = ({...props}) => (<Input {...props} />);

...
        value: {
            description: 'Input',
            defaultValue: 0,
            table: {
                type: {
                    summary: 'number'
                },
            },
            control: {
                type: 'number'
            }
        }
...

@kevinzang
Copy link

I get this error on 6.1.18, but manually setting defaultValue: 0 does fix it. The autogenerated argTypes from react-docgen has defaultValue: '0'.

@shilman
Copy link
Member

shilman commented Feb 25, 2021

@kevinzang can you try in 6.2-beta? we recently fixed a bunch of bugs around default value handling

@kevinzang
Copy link

@shilman with 6.2.0-beta.3 I can still reproduce this error in two ways:

  1. With a required number prop, I see the error as soon as I navigate from another story (Default) to one that uses controls (WithControls).
Sample code

foo.js

import PropTypes from 'prop-types';
import React from 'react';

export default class Foo extends React.Component {
    static propTypes = {
        foo: PropTypes.number.isRequired,
    };

    render() {
        return this.props.foo;
    }
}

foo.stories.js

import React from 'react';

import Foo from './foo';

export default {title: 'Foo', component: Foo};

export const Default = () => <Foo foo={10} />;

export const WithControls = args => <Foo {...args} />;

WithControls.args = {foo: 10};

  1. With an optional number prop, the above issue doesn't happen (which is probably what you fixed), but the error still happens when I empty the control.
Sample code

Change the Foo component from the above sample code to

static propTypes = {
    foo: PropTypes.number,
};

static defaultProps = {
    foo: 0,
};
Demo

controlled-to-uncontrolled

@shilman shilman reopened this Feb 26, 2021
@shilman shilman added the P1 label Feb 26, 2021
@shilman shilman removed the tracked label Mar 30, 2021
@anilanar
Copy link

anilanar commented Apr 8, 2021

I can reproduce this using v6.2.5 with react-docgen-typescript via 0 config setup, for React properties that are optional and whose types are number.

@miniskylab
Copy link

I can reproduce this too using v6.2.9 with react-docgen-typescript
I used the below piece of code:

// file name: component.stories.mdx

<Story
    name="Bug"
    argTypes={{
        test: {
            control: {
                type: "number"
            }
        }
    }}
>
    {args => <div>bug</div>}
</Story>

Screenshot:

Capture

Initially, Storybook rendered a blank numeric input field control and the console was empty. However, when I typed 1 in the numeric input field control the error appeared.

@shilman shilman removed this from the 6.0.x milestone Jul 14, 2021
@simlmx
Copy link

simlmx commented Dec 26, 2021

Adding a default value for the option fixes it for me:

 export default {
   component: SomeComponent,
   title: "Components/SomeComponent",
   argTypes: {
     myNumber: {
       control: {
         type: "range",
         min: 2,
         max: 7,
       },
     }
   },
   // This next blob is the fix!
   args: {
     myNumber: 5,
   },
 };

@shilman shilman removed the P1 label Oct 18, 2022
@shilman shilman removed the todo label Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants