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

Props with defaultProps of undefined show up. #96

Closed
leonelgalan opened this issue Jan 17, 2020 · 5 comments · Fixed by #97
Closed

Props with defaultProps of undefined show up. #96

leonelgalan opened this issue Jan 17, 2020 · 5 comments · Fixed by #97
Labels

Comments

@leonelgalan
Copy link
Contributor

leonelgalan commented Jan 17, 2020

Story definition:

<Checkbox
  onChange={onChange}
  value="yes"
  label="Check the Box"
/>

Storybook's JSX:

<Checkbox
  checked={false}
  color={undefined}
  id={undefined}
  label="Check the Box"
  name={undefined}
  onChange={action('onChange')}
  value="yes"
/>

Looking for a solution I noticed a PR that just got merged in react-element-to-jsx-string, but react-element-to-jsx-string is locked to ^14.0.3.

It allows for filterProps to be a function, so one could exclude props where the value is undefined.

14.3.0 was just released. There are no breaking changes since 14.0.3, but features that might benefit the community.

leonelgalan added a commit to leonelgalan/addon-jsx that referenced this issue Jan 21, 2020
This update allows `filterProps` to be a function (`(val: any, key: string) => boolean`).
It also includes Typescript declaration file.

A filterProps function (`filterProps: (val) => val !== undefined`) allows to hide props
with defaultValue of `undefined`. Closes storybookjs#96.
@leonelgalan
Copy link
Contributor Author

While preparing the PR (#97) I noticed 14.3.0 wouldn't work. Since 14.3.1 was released and it includes the fixes needed (algolia/react-element-to-jsx-string#516)

@hipstersmoothie
Copy link
Contributor

🚀 Issue was released in v7.1.14 🚀

@hipstersmoothie
Copy link
Contributor

🚀 Issue was released in v7.1.14 🚀

@eduludi
Copy link

eduludi commented Jul 13, 2020

IMO this should be set as a default, or at least be added to the documentation.

For those looking how to solve this, set this in your storybook configuration file:

addParameters({
  jsx: {
    filterProps: val => val !== undefined,
  },
})

@hipstersmoothie
Copy link
Contributor

I'm okay with that. Make a PR and i'll merge it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants