mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-05 16:11:33 +08:00
Merge pull request #19860 from gitstart/vue/add-v-on-render
Vue: Update events binding in Vue render
This commit is contained in:
commit
c754d638f2
@ -24,9 +24,6 @@ export const UseState = {
|
||||
],
|
||||
play: async ({ canvasElement }: PlayFunctionContext<any>) => {
|
||||
const button = await within(canvasElement).findByText('Clicked 0 times');
|
||||
// FIXME: onClick does not properly register in vue2
|
||||
// https://github.com/storybookjs/storybook/issues/19318
|
||||
if (globalThis.storybookRenderer === 'vue') return;
|
||||
|
||||
await userEvent.click(button);
|
||||
await within(canvasElement).findByText('Clicked 1 times');
|
||||
|
@ -75,10 +75,27 @@ export const render: ArgsStoryFn<VueRenderer> = (args, context) => {
|
||||
componentName = component.__docgenInfo?.displayName;
|
||||
}
|
||||
|
||||
let eventsBinding = '';
|
||||
const eventProps = Object.values(argTypes)
|
||||
.filter((argType) => argType?.table?.category === 'events')
|
||||
.map((argType) => argType.name);
|
||||
|
||||
if (eventProps.length) {
|
||||
eventsBinding = eventProps.map((name) => `@${name}="$props.${name}"`).join(' ');
|
||||
eventsBinding = `${eventsBinding} `;
|
||||
}
|
||||
|
||||
return {
|
||||
props: Object.keys(argTypes),
|
||||
components: { [componentName]: component },
|
||||
template: `<${componentName} v-bind="$props" />`,
|
||||
template: `<${componentName} ${eventsBinding}v-bind="filterOutEventProps($props)" />`,
|
||||
methods: {
|
||||
filterOutEventProps(props: object) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(props).filter(([key]) => !eventProps.includes(key))
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user