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

Wrong prop types displayed in Storybook props table #2760

Open
mimarz opened this issue Nov 11, 2024 · 4 comments
Open

Wrong prop types displayed in Storybook props table #2760

mimarz opened this issue Nov 11, 2024 · 4 comments
Labels
🐛 bug Something isn't working 📔 storybook storybook.designsystemet.no

Comments

@mimarz
Copy link
Collaborator

mimarz commented Nov 11, 2024

When declaring a default value for native props in our preview story, wrong type is displayed in the props table. It uses the type for the value declared in the preview story instead of the actual type on the component.

Notes;

  • Alert has defined a string default value for children in its preview story, resulting in string being shown as the prop type instead of the native one, ReactNode
  • Maybe there is a solution in tweaking our reactDocgen settings/parsing
@mimarz mimarz converted this from a draft issue Nov 11, 2024
@mimarz mimarz added 🐛 bug Something isn't working 📔 storybook storybook.designsystemet.no labels Nov 11, 2024
@elaffen
Copy link
Contributor

elaffen commented Nov 11, 2024

Why should you list the children prop unless it's something else than the default ReactNode?

  • One reason could be that you want to add some valuable description/doc for the usage of children in the component.
  • You would like the type to be something else. For example 'string'
    There is an option for reactDocgenTypescriptOptions which will let you skip the listing of children: skipChildrenPropWithoutDoc: false,

@mimarz
Copy link
Collaborator Author

mimarz commented Nov 11, 2024

Aye, having tested a bit this looks to be related specifically to the children prop.

Its a good point of declaring jsdoc for children for more composed component such as Accordion, where we expect the children to be multiple Accordion.Item, but for something like Button maybe not so, we still want that to be?

I agree we should document when children is expected to be a set of specific sub-components.

Lets do some testing with the skipChildrenPropWithoutDoc option. Maybe that can be a quick fix for now and we'll get some proper jsdoc for the children prop sorted later.

@elaffen
Copy link
Contributor

elaffen commented Nov 11, 2024

Your propFilter prevents the children from being Docgenerated. That is why you need to define the prop yourself or tweak the filter.

? !/node_modules/.test(prop.parent.fileName)

But because you have specified that children arg in the Alert-story, Storybook guesses that children is of type 'string'

children: 'En beskjed det er viktig at brukeren ser',

If you change the value of children in the story to true children: true, in Alert.stories.tsx line 24, Storybook will list the prop as boolean.

@mimarz mimarz moved this from 🔵 Inbox to 📄 Todo in Team Design System Nov 12, 2024
@mimarz
Copy link
Collaborator Author

mimarz commented Nov 13, 2024

Your propFilter prevents the children from being Docgenerated. That is why you need to define the prop yourself or tweak the filter.

? !/node_modules/.test(prop.parent.fileName)

But because you have specified that children arg in the Alert-story, Storybook guesses that children is of type 'string'

children: 'En beskjed det er viktig at brukeren ser',

If you change the value of children in the story to true children: true, in Alert.stories.tsx line 24, Storybook will list the prop as boolean.

yeah, good catch! We added that filter because of performance problems locally with react-docgen scanning for types everywhere. We'll have to fix this somehow so that we get the correct types for children on all our components :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 📔 storybook storybook.designsystemet.no
Projects
Status: 📄 Todo
Development

No branches or pull requests

2 participants