From cce53da4eb105972b6fce136e5e0253cea7dc4e2 Mon Sep 17 00:00:00 2001 From: Anton Alexandrenok Date: Tue, 21 Feb 2017 10:12:53 +0300 Subject: [PATCH 1/2] Added .focus() instance method --- src/Creatable.js | 4 ++++ test/Creatable-test.js | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Creatable.js b/src/Creatable.js index 145c568aa3..f1f3fe33e5 100644 --- a/src/Creatable.js +++ b/src/Creatable.js @@ -203,6 +203,10 @@ const Creatable = React.createClass({ } }, + focus () { + this.select.focus(); + }, + render () { const { newOptionCreator, diff --git a/test/Creatable-test.js b/test/Creatable-test.js index 968478fd9a..45014c105a 100644 --- a/test/Creatable-test.js +++ b/test/Creatable-test.js @@ -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); + }); + }); }); From 5513893df6bbd3eb06470c29e2120971202baa50 Mon Sep 17 00:00:00 2001 From: Anton Alexandrenok Date: Tue, 14 Mar 2017 12:03:35 +0300 Subject: [PATCH 2/2] 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); + }); + }); });