Using controls with svelte children #32132
Replies: 1 comment 1 reply
-
Hi @brendan-morin! I'm Dosu and I’m helping the storybook team. Storybook controls haven't traditionally worked with Svelte slot content (children) because controls/args are mapped to props, not slots. That's why your attempts to control the button text via the However, there's now a new feature that lets you control the default slot using the framework: {
name: '@storybook/sveltekit',
options: {
childrenArgAsDefaultSlot: true
}
} With this enabled, you can use controls to set the <Story
name="Default"
args={{ children: 'Button' }}
/> Now, the controls panel will let you edit the button text live. The This feature is opt-in for now and will be enabled by default in a future Storybook major release. More details and examples are in the pull request and docs. Let me know if you want a more detailed example or run into any issues! To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hi! I'm trying to sort out how to use controls in conjunction with e.g. defaults for values that are used in svelte children. I have this working for a default for stories where I have a Button component. But the way the button component accepts text is via svelte's children (e.g a snippet), and not e.g. a simple text parameter.
So this does work for setting the default value to Button for everything, but it seems to preclude me from also using Control to set button text. It's really a minor thing (and I understand this doesn't fully generalize), but I was wondering if there is some way to pass values in using controls here. I tried this and it does not seem to work:
I also tried a few variants of using snippets here to no avail. Any advice or thoughts on this would be welcome. This is non-blocking, but I am just trying to understand how to more fluently use the framework in this case.
Additional information
main.ts
Create a reproduction
No response
Beta Was this translation helpful? Give feedback.
All reactions