Skip to content

Commit

Permalink
Added .focus() to AsyncCreatable
Browse files Browse the repository at this point in the history
  • Loading branch information
the-spyke committed Mar 14, 2017
1 parent cce53da commit 5513893
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/AsyncCreatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ function reduce(obj, props = {}){
const AsyncCreatable = React.createClass({
displayName: 'AsyncCreatableSelect',

focus () {
this.select.focus();
},

render () {
return (
<Select.Async {...this.props}>
Expand All @@ -26,6 +30,7 @@ const AsyncCreatable = React.createClass({
return asyncProps.onInputChange(input);
}}
ref={(ref) => {
this.select = ref;
creatableProps.ref(ref);
asyncProps.ref(ref);
}}
Expand Down
13 changes: 13 additions & 0 deletions test/AsyncCreatable-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,17 @@ describe('AsyncCreatable', () => {
class: ['foo']
});
});

describe('.focus()', () => {
beforeEach(() => {
createControl({});
TestUtils.Simulate.blur(filterInputNode);
});

it('focuses the search input', () => {
expect(filterInputNode, 'not to equal', document.activeElement);
creatableInstance.focus();
expect(filterInputNode, 'to equal', document.activeElement);
});
});
});

0 comments on commit 5513893

Please sign in to comment.