Skip to content

Commit

Permalink
feat(TextArea): add focus() method (#1602)
Browse files Browse the repository at this point in the history
* Add focus method to the TextArea component

* fix(Transition): fix lint issues in tests
  • Loading branch information
gnowoel authored and levithomason committed Apr 21, 2017
1 parent 91a0710 commit af2807f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/addons/TextArea/TextArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
32 changes: 21 additions & 11 deletions test/specs/addons/TextArea/TextArea-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(<TextArea {...props} />)

wrapper.find('textarea').simulate('change', e)
describe('focus', () => {
it('can be set via a ref', () => {
wrapperMount(<TextArea />)
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)
})
})

Expand Down Expand Up @@ -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(<TextArea {...props} />)

wrapper.find('textarea').simulate('change', e)

spy.should.have.been.calledOnce()
spy.should.have.been.calledWithMatch(e, { ...props, value: e.target.value })
})
})
})

0 comments on commit af2807f

Please sign in to comment.