diff --git a/src/TextField.js b/src/TextField.js index ac9efae..ba767b1 100755 --- a/src/TextField.js +++ b/src/TextField.js @@ -2,6 +2,9 @@ import TextField from 'material-ui/TextField' import createComponent from './createComponent' import mapError from './mapError' -export default createComponent(TextField, ({ defaultValue, ...props }) => - mapError(props) -) +export default createComponent(TextField, ({ + defaultValue, + ...props +}) => ({ + ...mapError(props) +})) diff --git a/src/__tests__/TextField.spec.js b/src/__tests__/TextField.spec.js index ad89a98..22bd600 100644 --- a/src/__tests__/TextField.spec.js +++ b/src/__tests__/TextField.spec.js @@ -21,7 +21,7 @@ describe('TextField', () => { value: 'Foo' } }).render() - ).toEqualJSX( {}} />) + ).toEqualJSX() }) it('renders a TextField with no error when not touched', () => { @@ -35,7 +35,7 @@ describe('TextField', () => { error: 'FooError' } }).render() - ).toEqualJSX( {}} />) + ).toEqualJSX() }) it('renders a TextField with an error', () => { @@ -56,7 +56,6 @@ describe('TextField', () => { value="Foo" error helperText="FooError" - ref={() => {}} /> ) }) @@ -72,7 +71,7 @@ describe('TextField', () => { warning: 'FooWarning' } }).render() - ).toEqualJSX( {}} />) + ).toEqualJSX() }) it('renders a TextField with an warning', () => { @@ -93,7 +92,6 @@ describe('TextField', () => { value="Foo" error helperText="FooWarning" - ref={() => {}} /> ) }) @@ -117,7 +115,6 @@ describe('TextField', () => { value="" error helperText="FooWarning" - ref={() => {}} /> ) }) diff --git a/src/createComponent.js b/src/createComponent.js index 4ee4c12..02d57b3 100755 --- a/src/createComponent.js +++ b/src/createComponent.js @@ -1,4 +1,5 @@ import { Component, createElement } from 'react' +import { isStateLess } from './utils'; /** * Creates a component class that renders the given Material UI component @@ -16,7 +17,7 @@ export default function createComponent(MaterialUIComponent, mapProps) { render() { return createElement(MaterialUIComponent, { ...mapProps(this.props), - ref: el => this.component = el + ref: (!isStateLess(MaterialUIComponent) ? el => this.component = el : null) }) } } diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..fcc53a2 --- /dev/null +++ b/src/utils.js @@ -0,0 +1 @@ +export const isStateLess = (Component) => !Component.prototype.render; \ No newline at end of file