Skip to content

Commit

Permalink
Remove refs for stateless component from MUI Fixes #188
Browse files Browse the repository at this point in the history
  • Loading branch information
mihirsoni committed Oct 29, 2017
1 parent 6e1862c commit 599841c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}))
9 changes: 3 additions & 6 deletions src/__tests__/TextField.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('TextField', () => {
value: 'Foo'
}
}).render()
).toEqualJSX(<TextField name="myText" value="Foo" ref={() => {}} />)
).toEqualJSX(<TextField name="myText" value="Foo" />)
})

it('renders a TextField with no error when not touched', () => {
Expand All @@ -35,7 +35,7 @@ describe('TextField', () => {
error: 'FooError'
}
}).render()
).toEqualJSX(<TextField name="myText" value="Foo" ref={() => {}} />)
).toEqualJSX(<TextField name="myText" value="Foo" />)
})

it('renders a TextField with an error', () => {
Expand All @@ -56,7 +56,6 @@ describe('TextField', () => {
value="Foo"
error
helperText="FooError"
ref={() => {}}
/>
)
})
Expand All @@ -72,7 +71,7 @@ describe('TextField', () => {
warning: 'FooWarning'
}
}).render()
).toEqualJSX(<TextField name="myText" value="Foo" ref={() => {}} />)
).toEqualJSX(<TextField name="myText" value="Foo" />)
})

it('renders a TextField with an warning', () => {
Expand All @@ -93,7 +92,6 @@ describe('TextField', () => {
value="Foo"
error
helperText="FooWarning"
ref={() => {}}
/>
)
})
Expand All @@ -117,7 +115,6 @@ describe('TextField', () => {
value=""
error
helperText="FooWarning"
ref={() => {}}
/>
)
})
Expand Down
3 changes: 2 additions & 1 deletion src/createComponent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, createElement } from 'react'
import { isStateLess } from './utils';

/**
* Creates a component class that renders the given Material UI component
Expand All @@ -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)
})
}
}
Expand Down
1 change: 1 addition & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isStateLess = (Component) => !Component.prototype.render;

0 comments on commit 599841c

Please sign in to comment.