Skip to content

Commit

Permalink
Merge pull request #1569 from the-spyke/fix-1437-creatable-no-focus
Browse files Browse the repository at this point in the history
Fix missing .focus() method in Creatable (#1437)
  • Loading branch information
JedWatson authored Mar 30, 2017
2 parents 5f7c4c6 + c3e9f46 commit 80943b4
Show file tree
Hide file tree
Showing 4 changed files with 35 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
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/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);
});
});
});
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 80943b4

Please sign in to comment.