Skip to content

Commit

Permalink
Merge pull request #13003 from zeckdude/fix/source-default-props
Browse files Browse the repository at this point in the history
Addon-docs: Hide React default props in source block
  • Loading branch information
shilman authored Nov 4, 2020
2 parents 4c21f14 + c3bb4f8 commit ff57dd1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions addons/docs/src/frameworks/react/jsxDecorator.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
import React from 'react';
import range from 'lodash/range';
import PropTypes from 'prop-types';
import addons, { StoryContext } from '@storybook/addons';
import { renderJsx, jsxDecorator } from './jsxDecorator';
import { SNIPPET_RENDERED } from '../../shared';
Expand Down Expand Up @@ -131,6 +132,27 @@ describe('renderJsx', () => {
</MyMemoComponent>
`);
});

it('should not add default props to string if the prop value has not changed', () => {
const Container = ({ className, children }: { className: string; children: string }) => {
return <div className={className}>{children}</div>;
};

Container.propTypes = {
children: PropTypes.string.isRequired,
className: PropTypes.string,
};

Container.defaultProps = {
className: 'super-container',
};

expect(renderJsx(<Container>yo dude</Container>, {})).toMatchInlineSnapshot(`
<div>
yo dude
</div>
`);
});
});

// @ts-ignore
Expand Down
1 change: 1 addition & 0 deletions addons/docs/src/frameworks/react/jsxDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const defaultOpts = {
skip: 0,
showFunctions: false,
enableBeautify: true,
showDefaultProps: false,
};

export const skipJsxRender = (context: StoryContext) => {
Expand Down

0 comments on commit ff57dd1

Please sign in to comment.