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

Add suppressClassNameWarning prop to supress classNames usage warnings #2156

Merged
merged 2 commits into from Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@ _The format is based on [Keep a Changelog](http://keepachangelog.com/) and this

`${Comp}`; // .sc-hash
```
- Add `suppressClassNameWarning` prop to disable warning when wrapping a React component with `styled()` and the `className` isn't used, by [@Fer0x](https://github.com/Fer0x) (see [#2156](https://github.com/styled-components/styled-components/pull/2156))

## [v4.0.2] - 2018-10-18

Expand Down
7 changes: 7 additions & 0 deletions src/utils/classNameUseCheckInjector.js
Expand Up @@ -13,6 +13,13 @@ export default (target: Object) => {
targetCDM.call(this);
}

if (
(target.props && target.props.suppressClassNameWarning) ||
(target.attrs && target.attrs.suppressClassNameWarning)
) {
return;
}

const classNames = elementClassName
.replace(/ +/g, ' ')
.trim()
Expand Down
16 changes: 16 additions & 0 deletions src/utils/test/classNameUseCheckInjector.test.js
Expand Up @@ -23,4 +23,20 @@ describe('classNameUseCheckInjector', () => {

ReactDOM.findDOMNode.mockRestore();
});

it('does not show a warning if suppressClassNameWarning is passed', () => {
const Comp = () => <div />;
const StyledComp = styled(Comp)``;

jest.spyOn(console, 'warn').mockImplementation(() => {});

renderIntoDocument(
<div>
<StyledComp />
<StyledComp suppressClassNameWarning />
</div>
);

expect(console.warn.mock.calls.length).toBe(1);
})
});