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

[Bug]: Using a template in Angular causes componentWrapperDecorator to appear in canvas code preview #24560

Closed
kaydeejay opened this issue Oct 23, 2023 · 0 comments · Fixed by #29069

Comments

@kaydeejay
Copy link

kaydeejay commented Oct 23, 2023

Describe the bug

Expected behavior: code added to the story using componentWrapperDecorator should not be added to the Canvas code preview window, regardless of whether a template is used.

Actual behavior: when using a template in combination with componentWrapperDecorator, the added wrapper appears in the Canvas code preview window.


Examples:

✔️ template
❌ wrapper

const meta: Meta<Button> = {
  title: 'Example/Button',
  component: Button,
  decorators: [
    // componentWrapperDecorator(story => `<div class="storybook-wrapper">${story}</div>`)
  ],
  tags: ['autodocs'],
  render: (args: Button) => ({
    props: {
      backgroundColor: null,
      ...args,
    },
    template: `<storybook-button ${argsToTemplate(args)}></storybook-button>`
  }),
  argTypes: {
    backgroundColor: {
      control: 'color',
    },
  },
};

result:

no-wrapper-code


✔️ wrapper
❌ template

const meta: Meta<Button> = {
  title: 'Example/Button',
  component: Button,
  decorators: [
    componentWrapperDecorator(story => `<div class="storybook-wrapper">${story}</div>`)
  ],
  tags: ['autodocs'],
  render: (args: Button) => ({
    props: {
      backgroundColor: null,
      ...args,
    },
    // template: `<storybook-button ${argsToTemplate(args)}></storybook-button>`
  }),
  argTypes: {
    backgroundColor: {
      control: 'color',
    },
  },
};

result:

same as above


✔️ wrapper
✔️ template

const meta: Meta<Button> = {
  title: 'Example/Button',
  component: Button,
  decorators: [
    componentWrapperDecorator(story => `<div class="storybook-wrapper">${story}</div>`)
  ],
  tags: ['autodocs'],
  render: (args: Button) => ({
    props: {
      backgroundColor: null,
      ...args,
    },
    template: `<storybook-button ${argsToTemplate(args)}></storybook-button>`
  }),
  argTypes: {
    backgroundColor: {
      control: 'color',
    },
  },
};

result:

visible-wrapper-code

To Reproduce

  1. Download this repository
  2. npm install
  3. npm run storybook
  4. comment/uncomment the componentWrapperDecorator and template on lines 13 and 21 of src/stories/Button.stories.ts

System

System:
    OS: Linux 6.5 Pop!_OS 22.04 LTS
    CPU: (16) x64 AMD Ryzen 7 3800XT 8-Core Processor
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm <----- active
  npmPackages:
    @storybook/addon-essentials: 7.5.1 => 7.5.1 
    @storybook/addon-interactions: 7.5.1 => 7.5.1 
    @storybook/addon-links: 7.5.1 => 7.5.1 
    @storybook/angular: 7.5.1 => 7.5.1 
    @storybook/blocks: 7.5.1 => 7.5.1 
    @storybook/testing-library: ^0.0.14-next.2 => 0.0.14-next.2 
    storybook: 7.5.1 => 7.5.1

Additional context

No response

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

Successfully merging a pull request may close this issue.

3 participants