Skip to content

Commit

Permalink
Added .focus() instance method
Browse files Browse the repository at this point in the history
  • Loading branch information
the-spyke committed Feb 21, 2017
1 parent 2249f26 commit cce53da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Creatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ const Creatable = React.createClass({
}
},

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

render () {
const {
newOptionCreator,
Expand Down
13 changes: 13 additions & 0 deletions test/Creatable-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,17 @@ describe('Creatable', () => {
createControl({ onInputKeyDown: event => done() });
return creatableInstance.onInputKeyDown({ keyCode: 97 });
});

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 cce53da

Please sign in to comment.