Skip to content

[Bug]: Preview config argTypes condition does not work anymore for optional props with undefined story arg #33188

@chbiel

Description

@chbiel

Describe the bug

Now when configuring a global argType in the preview config with an if condition using exists for a prop that is optional (can be undefined), it's not displayed, although present.
It feels like the exists behavior has changed from "exists as available prop" to "has a non empty value set" what more be truthy not exists.

argTypes: {
    theme: {
      description: 'Choose between light and dark theme.',
      control: { type: 'radio' },
      options: [undefined, 'light', 'dark'],
      mapping: {
        light: 'LIGHT,
        dark: 'DARK',
      },
      // THIS BROKE SOME WHEN IN STORYBOOK 10
      if: {
        arg: 'theme', // theme arg of type `theme?: 'LIGHT' | 'DARK'`
        exists: true,
      },
    },
  }

I added that into our code in storybook 9 and there it was showing as expected.

Reproduction link

https://stackblitz.com/edit/github-vfwgneid-wytzuv3u?file=src%2Fstories%2FButton.tsx,.storybook%2Fpreview.ts&preset=node

Reproduction steps

Look at the Button component (has an added theme prop), but it's not showing up in the controls.
Remove the if condition from .storybook/preview.ts argTypes.
See the theme control appear on the page again.
Also when setting the theme arg in the stories file to e.g. LIGHT makes it reapear.

System

Storybook Environment Info:

  System:
    OS: Linux 6.14 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
    CPU: (16) x64 AMD Ryzen 7 PRO 7840U w/ Radeon 780M Graphics
    Shell: 3.7.1 - /usr/bin/fish
  Binaries:
    Node: 22.20.0 - /home/dejhcb0c/.nvm/versions/node/v22.20.0/bin/node
    npm: 11.6.2 - /home/dejhcb0c/.nvm/versions/node/v22.20.0/bin/npm <----- active
  Browsers:
    Chrome: 142.0.7444.175
    Firefox: 145.0.1
  npmPackages:
    @storybook/addon-docs: 10.0.8 => 10.0.8 
    @storybook/react-vite: 10.0.8 => 10.0.8 
    storybook: 10.0.8 => 10.0.8 
    storybook-addon-tag-badges: 3.0.2 => 3.0.2

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions