-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
argTypes mapping doesn't work with Vue props #14420
Comments
Select example show here fails in Vue as a result |
I needed argTypes to inject complex data that could not be serialized to JSON, resulting in this console warning:
So while I haven't been able to get argTypes with mapping to work, presumably for the reasons mentioned in this issue, I found a workaround for my specific use-case: You can inject complex variables using the const Template: Story<Props> = (args, { argTypes }) => ({
components: {
MyComponent,
},
props: Object.keys(argTypes),
render: (h) => h('MyComponent', {
props: {
myComplexVariable,
...args,
},
}),
}); |
@tillsanders have you tried the https://storybook.js.org/docs/react/writing-stories/args#mapping-to-complex-arg-values |
@shilman I'm using v6.3.12. This is what I tried, but instead of the group variable, I only received the string 'Group': export default {
title: 'Components/Editor',
component: Editor,
argTypes: {
group: {
options: ['Group'],
mapping: {
'Group': group,
},
},
},
),
}; |
@ghengeveld does this look right to you? ☝️ |
The same happens to me on 6.3.12
then the Storybook throws in console Labels work fine though |
I can confirm I'm seeing the same behaviour. customNavLinks: {
description: 'Custom navigation links',
options: ['OptionA', 'OptionB', 'OptionC'],
mapping: {
OptionA: ['Array A'],
OptionB: ['Array B'],
OptionC: ['Array C']
},
control: {
type: 'select',
labels: {
OptionA: 'Label A',
OptionB: 'Label B',
OptionC: 'Label C'
}
}
}, The control labels are correctly appearing as "Label A", "Label B" and "Label C", but when I select one of them I see the following error:
|
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
This issue is still active. |
Can confirm that this is still an issue |
Facing the same issue |
+1 |
I've also just run into this with my Vue2 storybook. |
MWE: export const Default = (args, context) => {
return {
components: {
MyComponent,
},
data: () => ({ args }),
props: Object.keys(argTypes),
template: `<MyComponent v-bind="args" />`,
}
}
|
I said lots of silly things so let's go at it again. Mappings work in the docs renderer. That is because it always rerenders the whole component on control change. They do not work in the canvas renderer. I have tested on
In SB7, both canvas and docs share their rendering code and both exhibit the bug. The value is not mapped. Until this can be fixed, please find an updated MWE workaround: // Assuming you have MyComponent, and args
const Template = (storyArgs, { argTypes } => {
return {
computed: {
props() {
const finalProps = { ...this.$props }
// Reapply mappings to circumvent Storybook Vue 2 bug.
Object.entries(this.$props)
.filter(([key, value]) =>
Object.hasOwn(argTypes[key]?.mapping || {}, value),
)
.forEach(([key, value]) => {
finalProps[key] = argTypes[key].mapping[value]
})
return finalProps
},
},
props: Object.keys(argTypes),
template: `<MyComponent v-bind="props" />`,
}
}
Template.args = args |
@prashantpalikhe If you have a min, this is highly related to the last set of fixes you made to the Vue2 renderer. In fact, I'm a bit surprised they didn't solve this issue. |
With // Alert.stories.js
import AppAlert from './Alert.vue'
export default {
title: 'Alert',
component: AppAlert,
argTypes: {
title: {
control: 'text',
},
description: {
control: {
type: 'inline-radio',
},
options: ['none', 'inline', 'array', 'arraySingleOption'],
mapping: {
none: '',
inline: 'Description as string',
array: [
'Array of options - the first item',
'Array of options - the second item',
'Array of options - the third item',
],
arraySingleOption: ['Array of options - the only option'],
},
},
variant: {
options: ['info', 'error'],
control: 'inline-radio',
},
},
args: {
title: '',
description: 'inline',
variant: 'info',
},
}
const Template = (storyArgs, { argTypes }) => ({
components: { AppAlert },
props: Object.keys(argTypes),
computed: {
args() {
const finalProps = { ...storyArgs }
// Reapply mappings to circumvent Storybook bug.
// https://github.com/storybookjs/storybook/issues/14420
Object.entries(storyArgs)
.filter(([key, value]) => Object.hasOwn(argTypes[key]?.mapping || {}, value))
.forEach(([key, value]) => {
finalProps[key] = argTypes[key].mapping[value]
})
return finalProps
},
},
template: `<AppAlert v-bind="args" />`,
})
export const Default = Template.bind({})
export const Array = Template.bind({})
Array.args = {
description: 'array',
} |
On Storybook 7 with Vue 3, argtype mappings work much better: in both canvas and doc modes, clicking a control applies the mapped argtype value. I'm not able to test with Vue 2 any more though. But not everything works. In both modes, the default value for a mapped argtype is not mapped to the corresponding control, so the control looks like no value is selected. I'm making a separate ticket for this. |
this solution solved my problem, |
Describe the bug
When using the new
mapping
feature for an argType that corresponds to a prop of a Vue component, the mapping is applied to the value that is passed toargs
, but is not applied to the value of the prop that is passed to the component.To Reproduce
Steps to reproduce the behavior:
options
andmapping
keysExpected behavior
The mapping should be applied to the value of the prop, but it's not.
Code snippets
With this snippet, I expect the label of the button to change between
Short
,Medium text
andVery long text that...
(the mapped values) when the user clicks the radio buttons in the controls panel. Instead, the label of the button changes betweenshort
,medium
andlong
(the unmapped values).Interestingly, if you put
console.log( _args.label )
somewhere (either in the arrow function aboveVue.extend
, or in amounted
lifecycle hook), it printsShort
, indicating that the values in_args
are mapped correctly. That mapping just isn't applied to the props that are passed to the Vue component.(I'm using Vue 2 here, I haven't tested this with Vue 3.)
System
┆Issue is synchronized with this Asana task by Unito
The text was updated successfully, but these errors were encountered: