New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Actions don't show up in panel when using argTypesRegex
#15012
Comments
Hey @jonathanhuang13, I believe the problem is how you are typing your component. I personally have never seen such way of typing, I commonly see this: - const TestComponent: (props: Props) => JSX.Element = (props) => {
+ const TestComponent = (props: Props): JSX.Element => {
return (
<div onClick={props.onClickFoo}>Hello World</div>
);
}; If you do like that, and just remove the args altogether, it will work as intended: const Template: Story<Props> = (args) => <TestComponent {...args} />;
export const Base = Template.bind({});
- Base.args = {
- onClickFoo: () => console.log('Hello'), // Still buggy after commented out
- }; Actions will automatically detect properties based on the actions argTypesRegex and if there is no value being passed, it will fill the handler with an action, which will appear in the panel. If you are passing a value via args, it won't display any actions in the panel but rather call the callback you're passing. |
@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! |
I would like this to be reopened if possible. |
I had the same problem. type GoodComponentProps = { onClick: VoidFunction }; // OK
type GoodComponentProps2 = Pick<GoodComponentProps, 'onClick'>; // OK
// e.g.
import { ButtonProps as MUIButtonProps } from '@mui/material/Button';
type BadComponentProps = Pick<MUIButtonProps, 'onClick'>; // NG: Not work |
This does still seem to be an issue |
same issue here with third party types |
Same here with union types I have a modal component with export type ModalProps = {
...
/**
* Callback called when a dismissed action is taken
* @default undefined
*/
onClose?: () => void;
} and other modal components that use this one, their types are similar to this: export type DialogProps = Omit<ModalProps, 'children' | 'actionRequired' | 'message'>; On the Modal stories, the argTypesRegex works perfectly, on the Dialog or any other modal, it doesn't. @jonathanhuang13 , can we reopen this? |
Also not working for me in React when the underlying component is typed like export const Button = forwardRef<HTMLButtonElement, Props>(({children, ...props}, ref) => {
// ...
return (
<BaseButton {...props} ref={ref}>
{children}
</BaseButton>
);
}) |
@kasperpeulen could you check the aforementioned use cases? thanks <3 |
any news on this ? |
Shall we prioritize this? @shilman @vanessayuenn |
Any news? |
I have a component configured like below where I have the same issue. Note the export interface ComponentAProps = {
... // excluded for brevity
onChange?: (newValue: string) => void;
}
const ComponentA = () => {
const { ... } = useComponentAContext();
}
const ComponentAWithContext = (props: ComponentAProps) => <ComponentAContextProvider>
<ComponentA /></ComponentAContextProvider>;
export default ComponentAWithContext; import ComponentA from "./ComponentA"; // should import the context wrapped default export
const Template = (args) => {
// debugging - you can see here that Storybook isn't passing an `onChange` handler of it's own because of `argTypesRegex`. If it worked, you'll see it here.
console.log(args);
return <ComponentA {...args} />;
};
export const Basic = Template.bind({});
export default {
title: "ComponentA",
component: ComponentA,
parameters: {
componentSubtitle:
"A neat subtitle",
viewMode: "story",
actions: { argTypesRegex: "^on.*" },
},
}; I'm using Storybook ( 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) const Template = (args) => {
// debugging - shows an `onChange` that Storybook passed in called `actionHandler`. So actions work!
console.log(args);
return <ComponentA {...args} />;
};
export default {
title: "ComponentA",
component: ComponentA,
parameters: {
componentSubtitle:
"A neat subtitle",
viewMode: "story",
// doesn't wire up to the `onChange` prop sadly
actions: { argTypesRegex: "^on.*" },
},
// explicitly specifying argTypes works!
argTypes: {
onChange: {
action: "changed",
},
},
}; |
Doesn't work when doing a component like this either:
|
I can't reproduce it in the latest Storybook 8.0 alpha (8.0.0-alpha.11). I will close this. |
@valentinpalkovic ok but what about in SB7? |
8.0, still can't achieve this
export default {
parameters: {
actions: { argTypesRegex: '^on.*' },
},
} satisfies Preview
import { Meta, StoryObj } from '@storybook/react'
import { Button } from '.'
export default {
component: Button,
title: 'atoms/Button'
} satisfies Meta<typeof Button>
type Story = StoryObj<typeof Button>
export const Default: Story = {
args: {
variant: 'primary',
text: 'text'
}
} |
@rikusen0335 would you mind sharing the code of your Button component as well? Or even better, set it up here? https://storybook.new/ |
@yannbf Will try to make reproduction on playground! |
Describe the bug
Actions don't show up in the actions panel when using
argTypesRegex
parameter inpreview.js
or in the component.Reproduction
Here is the reproduction: https://github.com/jonathanhuang13/storybook-repro
There are two stories to see:
Works
story works with manually specifying the argTypesBuggy
story doesn't work and it uses theargTypesRegex
parameterSystem
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:However, using
argTypesRegex
does not work on the component level. I do see the console log in the console though:Additionally, putting the
argTypesRegex
inpreview.js
doesn't work either:The text was updated successfully, but these errors were encountered: