Storybook is having trouble with the Stencil camelCase @Prop feature

I'm currently working on a story within Storybook for a Stencil component. It appears that all props function as expected when they are in lowercase. However, when a prop is written in camelCase, it doesn't seem to work properly. I've attempted using both camelCase and 'dash-case', but nothing seems to resolve the issue.

The Stencil component code:

import {Component, Prop, h} from '@stencil/core';

@Component({
  tag: 'text-input',
  shadow: true,
})
export class TextInput {
  @Prop() label: string;
  @Prop() inputId: string;

  render() {
    return (
      <div class="text-input">
        <label htmlFor={this.inputId}>{this.label}</label>
        <input type="text" id={this.inputId} />
      </div>
    )
  }
}

The corresponding Storybook story:

export default {
  title: 'Components/Text Input',
  argTypes: {
    label: {control: 'text'},
    inputid : {control: 'text'},
  }
};

const Template = (args) => {
  let tag = `<text-input label="${args.label}" inputId="${args.inputid}"></text-input>`;
  return tag
};

export const Default = Template.bind({});
Default.args = {
  label: 'First name:',
  inputid: 'Input1'
};

In this case, inputId is the problematic prop while label works perfectly fine. Even renaming

inputId="${args.inputid}"
to
input-id="${args.inputid}"
does not resolve the issue. The only solution is to change the Stencil prop to all-lowercase inputid.

Any insights on how to address this challenge? Is there a way to maintain Stencil props in camelCase format and have them function correctly in Storybook?

Answer №1

It could be related to how you're formatting your argTypes and Default arguments, for instance, "inputid" is all in lowercase. You might want to consider trying the following adjustments:

export default {
  title: 'Components/Text Input',
  argTypes: {
    label: {control: 'text'},
    inputId : {control: 'text'},
  }
};

const Template = (args) => {
  let tag = `<text-input label="${args.label}" inputId="${args.inputId}"></text-input>`;
  return tag
};

export const Default = Template.bind({});
Default.args = {
  label: 'First name:',
  inputId: 'Input1'
};

You could also try creating your template without using string concatenation. For example:

const Template = ({ label, inputId }) => {
  const element = document.createElement('text-input');
  element.label = label;
  element.inputId = inputId;
  return rootEl;
};

This approach will simplify things when passing parameters of a different type than string.

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

Unraveling functions from a JavaScript promise in a web application using ExpressJS and NeDB

I have successfully implemented code that retrieves all users from my neDB-promisses: const fetchAllUsers = (res) => { db.find({}) .sort({ name: 1 }) .exec() .then( (content) => { res.status(2 ...

The issue of "URLSearchParams not being defined" arises during test execution using jest

Is there a way to utilize URLSearchParams while testing with Jest? Every time I attempt to do it, the following error occurs: ReferenceError: URLSearchParams is not defined ...

Identify the specific button that triggers a JavaScript function

Currently, I am working on an admin page that displays a list of posts using EJS for template rendering engine. <table> <tr> <th>Name</th> <th>Description</th> </tr> <% projects.for ...

Having trouble updating the DataTable with extra details retrieved from a new URL

I'm currently utilizing the DataTable plugin. After loading the DataTable, my aim is to reload the table, while keeping the existing content intact, and adding information gathered from a separate json file. However, I'm encountering an issue wh ...

The unexpected blank space appearing beneath my website as a result of images and videos placed on the

There seems to be some random white space on my website between the main body elements and the footer. Interestingly, removing the cat image and videoplayer eliminates this white space. However, I don't want to remove them completely, so I'm tryi ...

"Reposition all elements contained within a div that have a specific class

I'm completely new to Javascript and I've been trying to move all elements with a specific class inside a particular div. After doing some research, I found a solution that worked using IDs. However, when I tried to adapt it to work with classNam ...

"Vue.js integrates seamlessly with Tracking.js for advanced tracking

Has anyone successfully integrated the tracking.js library into a vueJS application? I followed these steps to install the package: npm install --save tracking After that, I defined the library in my main.js file like this: import tracking from 't ...

How can you exclude selected values in React-select?

Here is how I have defined my select component: this.state.list = [{label: "test1", value:1}, {label:"test2", value:2}, {label:"test3", value:3}] this.state.selected = [{label:"test2", value:2}] let listMap = this.state.list let list = this.state.list { ...

404 error occurs when attempting to load SVG files in Webpack 2

Recently, I delved into the world of webpack. However, I encountered a problem when trying to load an SVG file referenced in one of my CSS files. Despite trying various loaders such as this, that, and the other, I keep receiving a 404 error. Can anyone pro ...

Setting a cookie using express.js with a 'j' prefix

Trying to establish a cookie using res.cookie as shown below: res.cookie('userId',req.user._id); //cookie set here console.log(req.user._id); //correct value returned, eg abc However, I'm noticing j:"abc" in my cookie. What could be the re ...

What causes the AngularJS variable to receive a null value following an HTTP request?

Using AngularJS on the frontend, I have a variable named ttest defined before making an $http call. Subsequently, data is assigned to this variable. The value of ttest[0] is available within the $http function but not outside of it. angular.module(&apos ...

Using the plus operator in Typescript is not compatible with the type of functions

I am encountering an error in my Vue component with Typescript, even though I have correctly declared types. The error pertains to the line mentioned in the title of this issue and below is a simplified version of the component causing the problem: import ...

Tips for checking errors during the process of WRITING data to a stream

Currently, I am testing the errors thrown in various sections of the application. The app is designed to transfer a stream from the request (multipart file upload) through encryption to an S3 bucket. While I can successfully simulate an exception in the _ ...

In ReactJs, inputs are considered void element tags which means they should not contain any `children` or utilize the `dangerouslySetInnerHTML` attribute

I have developed a dynamic input type user interface component in React, where the name, description, etc. can change based on its usage. const CustomInput = props => { const { labelName, inputType, description, onChangeHandler, onBlurHandler, icon } ...

jQuery siblings toggling issue unresolved

I am new to jQuery and I'm trying to create a toggle effect between sibling divs. In other words, when I click to show the next div, the previous one should automatically close. Currently, the previous div doesn't close when the next one is opene ...

React: The difference between exporting components as default anonymously or with a name

When it comes to exporting React components, is there a difference in performance, side effects, or standards between using an anonymous component versus a named one? Anonymous Component Export import React from 'react'; export default ({ titl ...

Is there a way to apply multiple nested criteria to filter an object effectively?

I'm dealing with a specific object and my goal is to filter and retrieve players from both groups based on certain criteria like "show me all players where franchise = Marvel, and power= flight" but I am struggling with the filtering process at multip ...

Issues persist with AJAX call to servlet

Recently, I encountered an issue with my servlet when attempting to insert form input fields into the database. The servlet was working fine when utilizing the following code: <form action="CreateUserServlet"> However, upon implementing some form v ...

Steps for Creating a Private Constructor in a Module while Allowing External Construction

I am looking for a way to restrict the construction of a class within a module to only be possible through a helper function from that same module. This would prevent any external users of the class from constructing it without using the designated helper ...

Effortless Route Loading in React Using Typescript's AsyncComponent for Dynamic Loading

I have been experimenting with lazy loading routes in React by following the example provided in the documentation for implementing the AsyncComponent class. The tutorial I referenced can be found here. Below is the asyncComponent function written in ES6 f ...