Storybook: Knobs numbers return null instead of undefined

Created on 23 Apr 2019  路  8Comments  路  Source: storybookjs/storybook

Describe the bug
I know somebody would say that this is not an error,
but knobs 'number' dont work with default parameter values because
it returns null instead of undefined on empty string.

To Reproduce

  1. Create a React/Angular component with default value and write a story for it.
  2. When you delete all context from the knobs input in storybook the value in the component will be null instead of the default value.
    (And this is because default values only works with undefined and not null)

Expected behavior
expect undefined, not null

Code snippets
storybook/addons/knobs/src/converters.js
Line 18:

  toFloat: value => (value === '' ? null : parseFloat(value)),

Should be:

  toFloat: value => (value === '' ? undefined : parseFloat(value)),

bs and good in general :)

knobs has workaround inactive question / support

Most helpful comment

I dont believe it's a duplicate of #4487 but clearly related.

The problem with 'select' knobs require another solution then this does.

The 'number' knobs is because it's has been choosen at some point to return 'null'
in storybook/addons/knobs/src/converters.js for numbers that a empty string instead of undefined

All 8 comments

I think this is a dupe to https://github.com/storybooks/storybook/issues/4487

Right @Hypnosphi ?

Looks like a completely different issue to me

I dont believe it's a duplicate of #4487 but clearly related.

The problem with 'select' knobs require another solution then this does.

The 'number' knobs is because it's has been choosen at some point to return 'null'
in storybook/addons/knobs/src/converters.js for numbers that a empty string instead of undefined

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!

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!

Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

I'm experiencing the same issue as well.

This is my workaround that worked for me:

export const knobsStory = () => (
  <MyComponent myNum={number('My Number', 0.5) || undefined} />
);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

miljan-aleksic picture miljan-aleksic  路  3Comments

purplecones picture purplecones  路  3Comments

tirli picture tirli  路  3Comments

wahengchang picture wahengchang  路  3Comments

dnlsandiego picture dnlsandiego  路  3Comments