From 5513893df6bbd3eb06470c29e2120971202baa50 Mon Sep 17 00:00:00 2001 From: Anton Alexandrenok Date: Tue, 14 Mar 2017 12:03:35 +0300 Subject: [PATCH] Added .focus() to AsyncCreatable --- src/AsyncCreatable.js | 5 +++++ test/AsyncCreatable-test.js | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/AsyncCreatable.js b/src/AsyncCreatable.js index edc51ee10b..eb87b51459 100644 --- a/src/AsyncCreatable.js +++ b/src/AsyncCreatable.js @@ -13,6 +13,10 @@ function reduce(obj, props = {}){ const AsyncCreatable = React.createClass({ displayName: 'AsyncCreatableSelect', + focus () { + this.select.focus(); + }, + render () { return ( @@ -26,6 +30,7 @@ const AsyncCreatable = React.createClass({ return asyncProps.onInputChange(input); }} ref={(ref) => { + this.select = ref; creatableProps.ref(ref); asyncProps.ref(ref); }} diff --git a/test/AsyncCreatable-test.js b/test/AsyncCreatable-test.js index e1dd788238..de1e821126 100644 --- a/test/AsyncCreatable-test.js +++ b/test/AsyncCreatable-test.js @@ -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); + }); + }); });