question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extract Vue component props to another file will be ignored by Storybook.

See original GitHub issue

Describe the bug

If you write Vue component’s props in another file, and then import it and spread it to the props property section, Storybook won’t be able to detect those props.

To Reproduce

  1. vue create sb6-test with TypeScript template
  2. cd sb6-test
  3. npx sb@next init
  4. create two files

HelloWorldButton.vue

<template>
  <button :disabled="disabled">Hello World</button>
</template>

<script lang="ts">
import Vue from "vue";

export default Vue.extend({
  props: {
    disabled: Boolean,
  },
});
</script>

HelloWorldButton.stories.ts

import HelloWorldButton from "./HelloWorldButton.vue";

export default {
  title: "HelloWorldButton",
  component: HelloWorldButton,
};

export const Normal = (_: any, { argTypes }: any) => ({
  props: Object.keys(argTypes),
  components: { HelloWorldButton },
  template: `
    <HelloWorldButton v-bind="$props" />
  `,
});

Now everything looks fine

image

However, if you extract those props like this

<template>
  <button :disabled="disabled">Hello World</button>
</template>

<script lang="ts">
  import Vue from "vue";
  import { PropValidator } from "vue/types/options";

  const props = {
    disabled: Boolean as PropValidator<boolean>,
  };

  export default Vue.extend({
    props: {
      ...props,
    },
  });
</script>

Now the Storybook can’t detect those props right now.

image

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
elevatebartcommented, Nov 15, 2020

Hello @stefashkaa

Thank you for taking the time to explain your use case. Everything should indeed be working fine here, but you found a bug. I will be fixing it soon.

1reaction
scottnathcommented, May 10, 2021

@elevatebart do you have more info on what the bug might be? I’m seeing this error still in the latest storybook and vue3.

cheers

Read more comments on GitHub >

github_iconTop Results From Across the Web

Args - Storybook - JS.ORG
Args can be used to dynamically change props, slots, styles, inputs, etc. It allows Storybook and its addons to live edit components. You...
Read more >
Avoid mutating a prop directly since the value will be overwritten
I want my components to mutate props. I don't want the complexity of Vuex/boilerplate code emitting hundreds of events. But that's not the...
Read more >
Documenting components - Vue Styleguidist
In some rare cases, you might want to remove a prop from the documentation while keeping it in the code. The @ignore tag...
Read more >
Server-Side Rendering (SSR) - Vue.js
We will be using express for the next steps: Run npm install express; Create the following server.js file: js
Read more >
Dynamic behavior in Svelte: working with variables and props
svelte component will accept a todos attribute, which when omitted will be initialized to an empty array. Have a look at the app,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found