Skip to content
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

Class attribute stripped from rendered Vue source #13326

Closed
dcrall opened this issue Nov 29, 2020 · 4 comments
Closed

Class attribute stripped from rendered Vue source #13326

dcrall opened this issue Nov 29, 2020 · 4 comments

Comments

@dcrall
Copy link

dcrall commented Nov 29, 2020

I upgraded from 6.0 to 6.1 and noticed the new rendering for Vue stories as described in #11400. First of all, thank you for this work. It is an improvement overall. However, I noticed that both static and dynamic class attributes are being stripped from the source rendering removing important context from the story. Please see the following screenshots and note the two plain divs that start the template. They should both have a class attribute.

Storybook-6 0

storybook-6 1

The stories are defined in an MDX file. Here is the code for the story:

export const formLayoutArgTypes = {
  gridDef: {
    name: 'gridDef',
    type: { name: 'string', required: false },
    defaultValue: 'grid grid-cols-1 gap-4',
    description: 'Tailwind grid definition'
  },
  ...
}

export const GridTemplate = (args, { argTypes }) => ({
  props: Object.keys(argTypes),
  components: { AisInput },
  template: `
    <div class="container mx-auto mt-4">
      <div :class="gridDef">
        <AisInput id="first-1" label="First" description="You can go your own way" :class="firstClass" placeholder="First Name" />
        <AisInput id="last-1" label="Last" description="Don't stop believing" :class="lastClass" placeholder="Last Name" />
        <AisInput id="email-1" label="Email" description="So what, so what, so what you want?" :class="emailClass" />
      </div>
    </div>
  `,
});

<Canvas>
  <Story
    name="Simple Layout"
    args={{
      gridDef: 'grid grid-cols-1 gap-4',
    }}
    argTypes={{...formLayoutArgTypes}}
  >
    {GridTemplate.bind({})}
  </Story>
</Canvas>

<ArgsTable story="Simple Layout" />

Am I doing something wrong here?

@dcrall
Copy link
Author

dcrall commented Nov 29, 2020

@pocka, @shilman - I would appreciate your feedback. Thank you.

@shilman
Copy link
Member

shilman commented Nov 29, 2020

Thanks @dcrall, I'm guessing this is a bug in the vue rendering. As a temporary workaround you can set docs.source.type parameter to "code" to restore the old behavior.

pocka added a commit that referenced this issue Nov 29, 2020
#13326

Both static class (`class="foo"`) and dynamic class (`:class="..."`)
are ignored because Vue treats them as special attribute. They don't
exist in normal vnode.data.attrs nor componentOptions.propsData.
@pocka pocka self-assigned this Nov 29, 2020
@shilman
Copy link
Member

shilman commented Nov 29, 2020

Yippee!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.1.9 containing PR #13327 that references this issue. Upgrade today to the @latest NPM tag to try it out!

npx sb upgrade

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Nov 29, 2020
@dcrall
Copy link
Author

dcrall commented Nov 29, 2020

Perfect. I tested with 6.1.9, and everything looks great. Thank you for the quick turnaround.

It was also cool to see that class attributes tied to story args appear dynamically when a value is added.

Storybook-6 1 9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants