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

Knobs numbers return null instead of undefined #6591

Closed
alfnielsen opened this issue Apr 23, 2019 · 8 comments
Closed

Knobs numbers return null instead of undefined #6591

alfnielsen opened this issue Apr 23, 2019 · 8 comments

Comments

@alfnielsen
Copy link

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 :)

@shilman
Copy link
Member

shilman commented Apr 23, 2019

I think this is a dupe to #4487

Right @Hypnosphi ?

@shilman shilman added this to the 5.0.x milestone Apr 23, 2019
@Hypnosphi
Copy link
Member

Hypnosphi commented Apr 23, 2019

Looks like a completely different issue to me

@Hypnosphi Hypnosphi reopened this Apr 23, 2019
@alfnielsen
Copy link
Author

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

@stale
Copy link

stale bot commented May 15, 2019

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!

@stale stale bot added the inactive label May 15, 2019
@shilman shilman modified the milestones: 5.0.x, 5.1.x Jun 5, 2019
@stale stale bot removed inactive labels Jun 5, 2019
@stale
Copy link

stale bot commented Jun 26, 2019

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!

@stale stale bot added the inactive label Jun 26, 2019
@stale
Copy link

stale bot commented Jul 26, 2019

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!

@stale stale bot closed this as completed Jul 26, 2019
@LilyMGoh
Copy link

I'm experiencing the same issue as well.

@davidhorm
Copy link

davidhorm commented Dec 24, 2019

This is my workaround that worked for me:

export const knobsStory = () => (
  <MyComponent myNum={number('My Number', 0.5) || undefined} />
);

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

5 participants