storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
84.7k stars 9.33k forks source link

Text knob transforms characters #4445

Closed cichelero closed 6 years ago

cichelero commented 6 years ago
knob issue

Bug or support request summary

With storybook and knobs release candidate 4, I have the ' string misformated as in the image.

Steps to reproduce

Configure a text knob with text like You're great!, it will be displayed as You're great!.

Minimal repository reproducing the bug

Please specify which version of Storybook and optionally any affected addons that you're running

Affected platforms

Saw it on Chrome and Firefox

Screenshots / Screencast / Code Snippets (Optional)

import { withKnobs, text } from '@storybook/addon-knobs';

import Title from '../Title';

storiesOf('Knobs', module)
  .addDecorator(withKnobs)
  .add('Title', () => <Title text={text('text', "You're great!")} />);
brunoreis commented 6 years ago

I found the same behavior on object knob props on alpha.16

pho3nixf1re commented 6 years ago

Is there a workaround for this?

igor-dv commented 6 years ago

Knobs are using https://github.com/component/escape-html package to escapes ", ', &, <, and >.

To prevent escaping you can use it like this:

storiesOf(...)
  .add('name', () => {}, {
    knobs: {
      escapeHTML: false
    }
  })
pho3nixf1re commented 6 years ago

This can be applied globally by passing it to the decorator setup.

addDecorator(
  withKnobs({
    escapeHTML: false,
  })
);
sirberus commented 5 years ago

Using 4.1.11 across the board, only @igor-dv 's answer worked:

storiesOf(...)
  .add('name', () => {}, {
    knobs: {
      escapeHTML: false
    }
  })

This is in a Vue project where the knobs are being included directly in the components. It would be cleaner if escapeHtml was an option on text knobs - this way the logic will reside with the knob in the component. Please consider exposing this option.

aminimalanimal commented 4 years ago

fwiw, with the new exported story format, it goes under parameters:

export default {
  title: 'Base Component',
  component: { BaseComponent },
  decorators: [withKnobs],
  parameters: {
    knobs: {
      escapeHTML: false,
    },
  },
}
evans commented 3 years ago

I found adding the following to .storybook/preview.js gave me back the functionality of https://github.com/storybookjs/storybook/issues/4445#issuecomment-434775097 after upgrading to 6.x from 5.x

const parameters = {
  knobs: {
    escapeHTML: false,
  },
};

storybook docs for global parameters