storybook: Actions don't show up in panel when using `argTypesRegex`
Describe the bug
Actions don’t show up in the actions panel when using argTypesRegex parameter in preview.js or in the component.
Reproduction Here is the reproduction: https://github.com/jonathanhuang13/storybook-repro
npm install
npm run storybook
There are two stories to see:
- The
Worksstory works with manually specifying the argTypes - The
Buggystory doesn’t work and it uses theargTypesRegexparameter
System
Environment Info:
System:
OS: macOS 11.3.1
CPU: (8) x64 Apple M1
Binaries:
Node: 14.16.1 - ~/.asdf/installs/nodejs/14.16.1/bin/node
npm: 6.14.12 - ~/.asdf/installs/nodejs/14.16.1/bin/npm
Browsers:
Chrome: 90.0.4430.212
Safari: 14.1
npmPackages:
@storybook/addon-actions: ^6.2.9 => 6.2.9
@storybook/addon-essentials: ^6.2.9 => 6.2.9
@storybook/addon-links: ^6.2.9 => 6.2.9
@storybook/react: ^6.2.9 => 6.2.9
Additional context
This additional context is from the original repo, not the reproduced repo. I have a component that takes a required prop onClickFoo. With the following story, I can see actions in the action panel when I click the appropriate button:
// Working
import React from 'react';
import { Story, Meta } from '@storybook/react';
import Editor, { EditorProps } from 'components/editor';
export default {
title: 'Editor',
component: Editor,
argTypes: {
onClickFoo: { action: 'changed' }, // Specifying argTypes by hand works
},
} as Meta;
const Template: Story<EditorProps> = (args) => (
<div className="h-60">
<Editor {...args} />
</div>
);
export const Base = Template.bind({});
Base.args = {
prop1: 'prop1',
};
However, using argTypesRegex does not work on the component level. I do see the console log in the console though:
// Does not work
import React from 'react';
import { Story, Meta } from '@storybook/react';
import Editor, { EditorProps } from 'components/editor';
export default {
title: 'Editor',
component: Editor,
parameters: { actions: { argTypesRegex: '^on.*' } }, // Specifying parameters does not work
} as Meta;
const Template: Story<EditorProps> = (args) => (
<div className="h-60">
<Editor {...args} />
</div>
);
export const Base = Template.bind({});
Base.args = {
prop1: 'prop1',
onClickFoo: () => console.log('Hello world'), // Removing this causes error in storybook that 'onClickFoo' doesn't exist
};
Additionally, putting the argTypesRegex in preview.js doesn’t work either:
// .storybook/preview.js
export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
}
// Story
import React from 'react';
import { Story, Meta } from '@storybook/react';
import Editor, { EditorProps } from 'components/editor';
export default {
title: 'Editor',
component: Editor,
} as Meta;
const Template: Story<EditorProps> = (args) => (
<div className="h-60">
<Editor {...args} />
</div>
);
export const Base = Template.bind({});
Base.args = {
prop1: 'prop1',
onClickFoo: () => console.log('Hello world'),
};
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 14
- Comments: 20 (9 by maintainers)
Shall we prioritize this? @shilman @vanessayuenn
same issue here with third party types
I had the same problem. It seems to happen when picking from a third party types.
I would like this to be reopened if possible. I can confirm that this is a bug. Typing it with
Pick<ComponentProps<SomeComponent>, "onChange">does not work, puttingonChangein directly does. Apparently the Typescript support is a bit broken.@yannbf Will try to make reproduction on playground!
I have a component configured like below where I have the same issue. Note the
actions: { argTypesRegex: "^on.*" }setting in the default export in thestory.jsfile doesn’t wire up the proponChangein the component to the actions tab in storybook. Weirdly it only happens for a component configured like this… where there is a context wrapped version of the component that I’m actually trying to use in Storybook.I’m using Storybook (
@storybook:react@6.5.16).I’ve done some digging online and I found that making the following change to the default export is the only thing that worked (see https://storybook.js.org/docs/6.5/react/essentials/actions#action-args)
Any news?
@kasperpeulen could you check the aforementioned use cases? thanks ❤️
Also not working for me in React when the underlying component is typed like
Same here with union types
I have a modal component with
and other modal components that use this one, their types are similar to this:
On the Modal stories, the argTypesRegex works perfectly, on the Dialog or any other modal, it doesn’t.
@jonathanhuang13 , can we reopen this?
@yannbf Thanks for taking a look at this. I’ve confirmed that how you’ve typed it works. It’s strange how the other way of typing a component causes issues. I’ll go ahead and close this though. Thanks!