Skip to content

[Bug]: Storybook Webcomponent - Control Panel [type] does not support optional properties  #21789

@cgaube

Description

@cgaube

Describe the bug

function mapItem(item: TagItem, category: string): InputType {

item.type?.text 

Does not support fields that can be two or more different types or that can be undefined.

myField?: string

storybook will display a Set Object in the control panel

Screenshot 2023-03-27 at 11 27 01

this should be set as String and not object

I realize that if you have a property that has multiple types (it is bad) then storybook cannot decide which one to use

myField: string | boolean

but for optional properties, storybook should support it

To Reproduce

Given the custom element defined as

export class CustomElement extends LitElement {

  /**
  * Description of the field
  */
  @property()
  myCustomField?: string;

  // .....
}

the generated custom-elements.json will contain

{
             "kind": "field",
             "name": "myCustomField",
             "type": {
               "text": "string | undefined"
             },
             "description": "Description of the field",
             "attribute": "myCustomField"
           },

System

Environment Info:

  System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 18.14.0 - ~/.nvm/versions/node/v18.14.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.14.0/bin/yarn
    npm: 9.3.1 - ~/.nvm/versions/node/v18.14.0/bin/npm
  Browsers:
    Chrome: 111.0.5563.110
    Firefox: 111.0.1
    Safari: 16.3
  npmPackages:
    @storybook/addon-a11y: ^7.0.0-rc.8 => 7.0.0-rc.8
    @storybook/addon-actions: ^7.0.0-rc.8 => 7.0.0-rc.8
    @storybook/addon-docs: ^7.0.0-rc.8 => 7.0.0-rc.8
    @storybook/addon-essentials: ^7.0.0-rc.8 => 7.0.0-rc.8
    @storybook/addon-links: ^7.0.0-rc.8 => 7.0.0-rc.8
    @storybook/blocks: ^7.0.0-rc.8 => 7.0.0-rc.8
    @storybook/types: 7.0.0-alpha.44 => 7.0.0-alpha.44
    @storybook/web-components: ^7.0.0-rc.8 => 7.0.0-rc.8
    @storybook/web-components-vite: ^7.0.0-rc.8 => 7.0.0-rc.8


### Additional context

_No response_

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions