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 in a story are not passed if they're named the same way as in the Vue component #23

Open
tzhelyazkova opened this issue Aug 12, 2020 · 9 comments

Comments

@tzhelyazkova
Copy link

Describe the bug
Naming a prop in a story the same way the component's prop is named leads to a broken state where the property value is not passed to the component.
Both the story and the vue component use TypeScript.

Workaround
Naming the prop in the story differently from the respective prop in the component works.

To Reproduce

  1. Create a story in TypeScript for a Vue component that has properties.
  2. Define the property name in the story to be the same as the prop name in the component
  3. Pass the property in the template like template: '<Button :type="type" />'

Expected behavior
The prop value is passed to the component.

Code snippets

// Button.vue
<template>
	<button :class="[ 'wikit', 'wikit-Button', `wikit-Button--${ type }` ]">
		<slot />
	</button>
</template>

<script lang="ts">
import Vue from 'vue';
export default Vue.extend( {
	name: 'Button',
	props: {
		/**
		 * The type of the button
		 */
		type: {
			type: String,
			validator( value: string ): boolean {
				return [ 'neutral', 'progressive', 'destructive' ].includes( value );
			},
			default: 'neutral',
		},
	},
} );
</script>
// Button.stories.ts
import Button from '@/components/Button';
import { select } from '@storybook/addon-knobs';
import { Component } from 'vue';

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

export function normal(): Component {
	return {
		components: { Button },
		props: {
			// naming a prop the same way the component's prop is named leads to
			// a broken state where the property value is not passed to the component
			type: {
				default: select(
					'Type',
					[ 'neutral', 'progressive', 'destructive' ],
					'neutral',
				),
			},
		},
		template: '<Button v-html="content" :disabled="disabled" :type="type" />',
	};
}

System:

  System:
    OS: Linux 5.4 Ubuntu 18.04.4 LTS (Bionic Beaver)
  Binaries:
    Node: 12.17.0
    npm: 6.14.4
  Browsers:
    Chrome: 83.0.4103.116
    Firefox: 79.0
  npmPackages:
    @storybook/addon-a11y: ^6.0.4 => 6.0.4 
    @storybook/addon-docs: ^6.0.4 => 6.0.4 
    @storybook/addon-knobs: ^6.0.4 => 6.0.4 
    @storybook/vue: ^6.0.4 => 6.0.4 

I cannot think of anything wrong with either the Vue component or the story itself.

@github-actions
Copy link

github-actions bot commented Aug 13, 2020

Automention: Hey @Armanio @backbone87 @elevatebart @leoyli @pksunkara @pocka, you've been tagged! Can you give a hand here?

@Aaron-Pool
Copy link

Any chance you could set up a codepen, or a repo with a minimal reproduction of this behavior?

@HerrBertling
Copy link

I'm running into this right now – checking within the next days :)

@HerrBertling
Copy link

HerrBertling commented Aug 20, 2020

I've reproduced this here: https://github.com/HerrBertling/nuxt-ts-storybook-docs-issuealthough I'm not using addon-knobs but out of the box controls. The deployed Storybook can be found here: https://competent-beaver-af1f48.netlify.app/

All buttons have the same (default) values, although I've added specific variants via Template.bind({…}).

My issue might be different since it's using controls, but it seems to me that this is the same root issue (since controls should™ use the exact same naming convention)

EDIT: @tzhelyazkova I've added your case to the repo, it's also within the deployed storybook within the next minutes 😊

@HerrBertling
Copy link

Turns out: If I actually use the correct setup for the controls/args stuff, it works as expected (=> HerrBertling/nuxt-ts-storybook-docs-issue@7dd04d8 ) – the knobs issue remains, though.

I'll check that next since I'll most certainly run into this as well.

@shilman
Copy link
Member

shilman commented Aug 21, 2020

@HerrBertling i'd recommend using controls/args instead of knobs

@HerrBertling
Copy link

@HerrBertling i'd recommend using controls/args instead of knobs

That would definitely solve the problem and also solve this issue @tzhelyazkova – maybe it's a solution for you as well? You can see the correct usage here: https://github.com/HerrBertling/nuxt-ts-storybook-docs-issue/blob/main/components/MyButton/MyButton.stories.js

@adrianosmond
Copy link

I'm also experiencing this issue. I only see the behaviour occurring on the select knob - text, number, boolean and object are working fine for me.

After a little investigation it looks to me like knobs and docs are conflicting with each other in some way, as either removing the component: MyComponent from the story's default export or removing the docs addon entirely seems to make the select knob work again. This is obviously not a solution but might be useful info?

@stale
Copy link

stale bot commented Oct 4, 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 shilman transferred this issue from storybookjs/storybook May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants