Skip to content

Commit cce53da

Browse files
committed
Added .focus() instance method
1 parent 2249f26 commit cce53da

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Creatable.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ const Creatable = React.createClass({
203203
}
204204
},
205205

206+
focus () {
207+
this.select.focus();
208+
},
209+
206210
render () {
207211
const {
208212
newOptionCreator,

test/Creatable-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,17 @@ describe('Creatable', () => {
237237
createControl({ onInputKeyDown: event => done() });
238238
return creatableInstance.onInputKeyDown({ keyCode: 97 });
239239
});
240+
241+
describe('.focus()', () => {
242+
beforeEach(() => {
243+
createControl({});
244+
TestUtils.Simulate.blur(filterInputNode);
245+
});
246+
247+
it('focuses the search input', () => {
248+
expect(filterInputNode, 'not to equal', document.activeElement);
249+
creatableInstance.focus();
250+
expect(filterInputNode, 'to equal', document.activeElement);
251+
});
252+
});
240253
});

0 commit comments

Comments
 (0)