storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
84.7k stars 9.33k forks source link

[Bug]: Object control sets an empty object before user can enter keys and values #21189

Open james2hey opened 1 year ago

james2hey commented 1 year ago

Describe the bug

When a component has an optional object prop and it is set as an undefined arg, when trying to define the object keys, an empty object is automatically set as the arg value.

This causes issues for components which have required entries that couldn't be defined, as clicking "Set object" will set the arg to {} before any required entries could be defined.

To Reproduce

https://63f4f662ea2e878c745e00db-sfsgqnpqra.chromatic.com/?path=/docs/example-introduction--docs

System

Environment Info:

  System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 16.18.1 - ~/.nvm/versions/node/v16.18.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.18.1/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v16.18.1/bin/npm
  Browsers:
    Chrome: 110.0.5481.100
    Safari: 16.2
  npmPackages:
    @storybook/addon-essentials: ^7.0.0-beta.47 => 7.0.0-beta.52 
    @storybook/addon-interactions: ^7.0.0-beta.47 => 7.0.0-beta.52 
    @storybook/addon-links: ^7.0.0-beta.47 => 7.0.0-beta.52 
    @storybook/blocks: ^7.0.0-beta.47 => 7.0.0-beta.52 
    @storybook/node-logger: ^7.0.0-beta.47 => 7.0.0-beta.52 
    @storybook/preset-create-react-app: ^4.1.2 => 4.1.2 
    @storybook/react: ^7.0.0-beta.47 => 7.0.0-beta.52 
    @storybook/react-webpack5: ^7.0.0-beta.47 => 7.0.0-beta.52 
    @storybook/testing-library: ^0.0.14-next.1 => 0.0.14-next.1

Additional context

A longer term fix for this could be improved controls support for TS interfaces. In the short term, the {} just probably should not be set until the user has hit the enter key.

KeitelDOG commented 11 months ago

I just experience this issue, trying to set a simple user object like : { id: 2, name: 'KeitelDOG', image: '' }. And it automatically send an empty object {}, while the Typescript type User is uses for this props. I don't have to check the Props since that's what Typescript or PropTypes are there for.