What is the best way to send props to a component's story?

Struggling with incorporating stories into the vue-select component using Storybook, especially in more complex cases involving passing props or methods.

When attempting to pass props within the template it functions correctly:

storiesOf('VSelect', module)
.add('with labeled custom options', () => ({
        components: {VSelect},
        template:   `<v-select :options='[{value: "CA", label: "Canada"}, {value: "UK", label: "United Kingdom"}]' />`
    }))

However, I find this method less readable and prefer to pass them as separate props or data:

.add('with labeled custom options as props', () => ({
        components: {VSelect},
        props:      {options: [{value: "CA", label: "Canada"}, {value: "UK", label: "United Kingdom"}]},
        data:       {options: [{value: "CA", label: "Canada"}, {value: "UK", label: "United Kingdom"}]},
        template:   `<v-select />`
    }))

Unfortunately, neither data, nor props are recognized by Storybook - they appear to be disregarded.

Answer №1

Success! I was able to find a solution.

.add('using custom options as labeled props', () => ({
        components: {VSelect},
        data() {
            return {
                choices: [{value: "CA", label: "Canada"}, {value: "UK", label: "United Kingdom"}]
            }
        },
        template:   `<v-select :options="choices" />`
    }))

I discovered 2 issues with my previous method:

  • The passed data wasn't enclosed in a function
  • I should have only passed the data itself. Utilizing both props and data appeared to trigger Vue to issue a warning (The data property "options" is already declared as a prop.) and overlook the supplied data (despite it being just a warning rather than an error, which I found peculiar)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Function being called by Intersection Observer at an inappropriate moment

After running the page, the intersection observer behaves exactly as desired. However, upon reloading the page, I am automatically taken back to the top of the page (which is expected). Strangely though, when the viewport interacts with the target elemen ...

Using Jquery to input selected dropdown values into a text input field

Currently, I am facing some challenges in achieving this task. My goal is to have the selected option from a dropdown list called programs_dropdown added to a text field named programs_input, with the option values separated by commas. For example: php, j ...

A peculiar glitch in the graphic display

Something strange is happening with my CSS tabs - there seems to be a bug. When I click on the third tab, the vertical line to the left disappears. This doesn't happen in the example provided in the semantic-ui manual. I'm wondering what could be ...

The issue of React props malfunctioning within a for loop is causing some trouble

When passing the rating as a prop to the Star Rating component, I can access the rating value in the StarRating function. However, whenever it enters the for loop, the rating becomes invisible. import React from 'react' const StarRating = ({ rat ...

How the Material-UI Tooltip zIndex takes precedence over the MenuItem in the Select component

My issue is quite straightforward. I have a <Tooltip> component wrapping a <Select> component, and when I click the Select, the tooltip appears above the MenuItems like this: Expected behavior: https://i.sstatic.net/VOVmf.png Unexpected beha ...

Sending an array of objects over socket io: A step-by-step guide

Recently, I've been struggling with an issue when trying to send an array of objects through socket io. This is my server-side code: var addEntity = function(ent) { entityBag.push(ent); }; var entityBag = []; addEntity(new Circle({ ...

Displaying a PDF in a new browser tab using JavaScript after retrieving data with cURL

Seeking guidance here. I currently have a URL for Phantomjs that produces a PDF, but my goal is to generate the PDF on the server side. <script> $("#generatePDF").click(function(){ var fullLink = "<? echo $link ?>" $.ajax({ ...

executing a hook within _app.tsx in Next.js

The issue I'm facing involves the rendering of a hook that helps determine if my components are within the screen's view to trigger animations. This hook is executed in _app.tsx, however, it doesn't run when switching to another page. Oddly ...

What is the best way to interpret the JavaScript code within a Vue/Quasar project?

Sample Code: <script type="text/javascript" src="https://widget.example.com/widgets/<example_id>.js" async defer></script> I am looking to integrate this code into Quasar Framework and utilize it with Vue.js. Do you have any suggesti ...

What could be the reason for the Unknown term error I am now encountering in Nuxt?

Today, I encountered an issue with my Nuxt project that was previously running smoothly. The problem seems to be related to Vue Flickity, which includes a CSS file from the node_modules directory. This setup has been functioning correctly until now. Upon ...

jQuery click() error message: "Issue converting JavaScript parameter"

Let me set the scene for you: A user completes a form on my website, which is then submitted using AJAX (specifically jQuery's $.post method). Upon receiving a response, I dynamically add an element to the page that corresponds to the form that was ju ...

The absence of Gapi definition in a React application hinders access to the Google Sheets API

Trying to send data from an HTML Form in a React.js web app to a google sheet. The script tag has been added in index.html (tried in <head> and in <body>) but gapi remains undefined. <body> <noscript>You need to enable JavaScript ...

What is the best way to assign a series of radio buttons to an array within an Angular controller's model?

Let's say I have a controller that contains an array property named 'houses'. I want to use ng-repeat to display this array on a table row with a set of radio buttons (true/false, etc.). How can I ensure that selecting any of these radio but ...

Can you explain the contrast between aws-amplify-react and @aws-amplify/ui-react?

I have come across multiple sources recommending the use of aws-amplify-react, but in the documentation for getting started with React, I found a different package @aws-amplify/ui-react that utilizes the module withAuthentication (which is also present in ...

Tips for importing modules in React JS/Next JS + Typescript as 'components/filename' rather than '../../../components/filename'

Is there a way to import pages, components, and containers directly using syntax like 'components/filename' or '@components/filename', rather than having to specify the full path to the parent folder such as '../../components/filen ...

One effective method for populating my form following the retrieval of JSON data

Currently, I am working on a VueJs project where I am fetching data from a Mysql database using Axios. My next step is to implement an edit option for user profiles. I am wondering what the most efficient method is for populating the form with the fetche ...

At what point are functions executed? What methods can I use to manage their execution?

Looking to make a simple call to an API using jQuery's $.get() function as a JS beginner. The issue I'm facing is that the function seems to be called randomly rather than where I expect it in my code. I am open to either doing everything inside ...

Refresh the table every couple of seconds

I need to regularly update a table every two to three seconds or in real-time if possible. The current method I tried caused the table to flash constantly, making it difficult to read and straining on the eyes. Would jQuery and Ajax solve this issue? How c ...

Jquery event handlers are not functioning properly on dynamically added iframes with constantly changing content

I have added a dynamic iframe to the document using jQuery on document ready function. $( document ).ready(function() { $("body").append(renderIframe()); });} ` The iframe is rendered through this function function renderIframe(){ return [ ...

Ways to generate a unique random number from an Array without repetition using Javascript

Looking to retrieve a random number from an array of numbers known as cardNumbertemp. function shuffleCard(){ randomized = Math.floor(Math.random()*cardNumbertemp.length); for (var i = 0; i < cardNumbertemp.length; i++){ ...