Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing .focus() method in Creatable (#1437) #1569

Merged
merged 3 commits into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
});