Open alexbjorlig opened 5 months ago
Replace
actions: {
handles: [ 'click'],
},
with:
argTypes: {
click: { action: "click" },
},
Did you try what is recommended in the documentation ?
See https://github.com/storybookjs/addon-svelte-csf/blob/main/README.md?plain=1#L63
Hi @j3rem1e
I might be missing somehow very obvious, but it does not seem to work for me 😓
(with this code I don't get anything in the Actions tab). Created a branch here, but the story is here:
<script context="module">
import Button from "./Button.svelte";
export const meta = {
title: 'Buttons',
tags: ['autodocs'],
component: Button,
args: {
size: 'medium',
label: 'test-story'
},
};
function handleClick() {
console.log('click called')
}
</script>
<script lang="ts">
import { Story } from '@storybook/addon-svelte-csf';
</script>
<Story name="Primary" let:args>
<Button {...args} on:click on:click={handleClick} />
</Story>
Your Button component doesn't dispatch a 'click' event but a 'testEvent'.
Your Button component doesn't dispatch a 'click' event but a 'testEvent'.
It does, check it here.
But again, the whole motivation for this question is not click events but how to make custom events show up in the actions tab 🤔
Sorry but it doesn't 😅
on:click is not forwarded. You use it with a handler which dispatch a testEvent. The parent component doesn't receive the click event.
But again, the whole motivation for this question is not click events but how to make custom events show up in the actions tab 🤔
Of course. But you can't subscribe to events not dispatched by your component.
Thanks so much for helping out @j3rem1e 👍 I updated the code to this now <Button {...args} on:testEvent/>
and I actually see the custom event 🔥
How would you recommend that I detect if the button was pressed in an interaction test now? I tried with this implementation, but it times out 🤔
play: async ({ args, canvasElement }) => {
const canvas = within(canvasElement);
const buttons = canvas.getAllByRole('button');
const button = buttons[0];
const eventPromise = new Promise((resolve) => {
button.addEventListener('testEvent', resolve, { once: true });
});
await Promise.all([
userEvent.click(button),
waitFor(() => eventPromise)
])
// await waitFor(() => expect(args.on).toHaveBeenCalled());
},
Updated code here.
Describe the bug
I'm pretty new to Storybook, so I don't know if this is the right place, but would really like my Svelte custom events to be shown here:
Steps to reproduce the behavior
npm run storybook
Expected behavior
Both click event and custom svelte event.
Screenshots and/or logs
It only shows the click event.
Button.stories.svelte
Environment
Additional context
Check repo for details here: https://github.com/21RISK/svelte-storybook-events