diff --git a/src/addons/TextArea/TextArea.js b/src/addons/TextArea/TextArea.js
index 0fb75739ca..cd24ba9804 100644
--- a/src/addons/TextArea/TextArea.js
+++ b/src/addons/TextArea/TextArea.js
@@ -54,6 +54,8 @@ class TextArea extends Component {
}
}
+ focus = () => (this.ref.focus())
+
handleChange = (e) => {
const { onChange } = this.props
if (onChange) onChange(e, { ...this.props, value: e.target && e.target.value })
diff --git a/test/specs/addons/TextArea/TextArea-test.js b/test/specs/addons/TextArea/TextArea-test.js
index 454614ee22..36e1c3979d 100644
--- a/test/specs/addons/TextArea/TextArea-test.js
+++ b/test/specs/addons/TextArea/TextArea-test.js
@@ -40,18 +40,13 @@ describe('TextArea', () => {
},
})
- describe('onChange', () => {
- it('is called with (e, data) on change', () => {
- const spy = sandbox.spy()
- const e = { target: { value: 'name' } }
- const props = { 'data-foo': 'bar', onChange: spy }
-
- wrapperShallow()
-
- wrapper.find('textarea').simulate('change', e)
+ describe('focus', () => {
+ it('can be set via a ref', () => {
+ wrapperMount()
+ const element = document.querySelector('textarea')
- spy.should.have.been.calledOnce()
- spy.should.have.been.calledWithMatch(e, { ...props, value: e.target.value })
+ wrapper.instance().focus()
+ document.activeElement.should.equal(element)
})
})
@@ -123,4 +118,19 @@ describe('TextArea', () => {
assertHeight('') // no height
})
})
+
+ describe('onChange', () => {
+ it('is called with (e, data) on change', () => {
+ const spy = sandbox.spy()
+ const e = { target: { value: 'name' } }
+ const props = { 'data-foo': 'bar', onChange: spy }
+
+ wrapperShallow()
+
+ wrapper.find('textarea').simulate('change', e)
+
+ spy.should.have.been.calledOnce()
+ spy.should.have.been.calledWithMatch(e, { ...props, value: e.target.value })
+ })
+ })
})