diff --git a/src/Async.js b/src/Async.js index c444a37093..d69afbb331 100644 --- a/src/Async.js +++ b/src/Async.js @@ -176,6 +176,10 @@ export default class Async extends Component { return searchPromptText; } + focus () { + this.select.focus(); + } + render () { const { children, loadingPlaceholder, placeholder } = this.props; const { isLoading, options } = this.state; diff --git a/test/Async-test.js b/test/Async-test.js index c49e60b5ba..8742e315ff 100644 --- a/test/Async-test.js +++ b/test/Async-test.js @@ -434,4 +434,17 @@ describe('Async', () => { return expect(onInputChange, 'was called times', 1); }); }); + + describe('.focus()', () => { + beforeEach(() => { + createControl({}); + }); + + it('focuses the search input', () => { + var input = asyncNode.querySelector('input'); + expect(input, 'not to equal', document.activeElement); + asyncInstance.focus(); + expect(input, 'to equal', document.activeElement); + }); + }); }); diff --git a/test/Select-test.js b/test/Select-test.js index 6614b972b9..d8df285436 100644 --- a/test/Select-test.js +++ b/test/Select-test.js @@ -3880,4 +3880,17 @@ describe('Select', () => { }); }); }); + + describe('.focus()', () => { + beforeEach(() => { + instance = createControl({}); + }); + + it('focuses the search input', () => { + var input = ReactDOM.findDOMNode(instance.input).querySelector('input'); + expect(input, 'not to equal', document.activeElement); + instance.focus(); + expect(input, 'to equal', document.activeElement); + }); + }); });