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

Re-added the focus() method on Select.Async #1331

Merged
merged 2 commits into from
Jan 31, 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
4 changes: 4 additions & 0 deletions src/Async.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions test/Async-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
13 changes: 13 additions & 0 deletions test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3799,4 +3799,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);
});
});
});