Skip to content

Commit

Permalink
Merge pull request #19860 from gitstart/vue/add-v-on-render
Browse files Browse the repository at this point in the history
Vue: Update events binding in Vue render
  • Loading branch information
ndelangen authored Jan 18, 2023
2 parents 952b7a6 + d32ba1a commit c754d63
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 0 additions & 3 deletions code/lib/store/template/stories/hooks.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
19 changes: 18 additions & 1 deletion code/renderers/vue/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
},
},
};
};

Expand Down

0 comments on commit c754d63

Please sign in to comment.