Skip to content

Commit

Permalink
fix(searchBox): force cursor position to be at the end of the query
Browse files Browse the repository at this point in the history
fixes #946
  • Loading branch information
vvo committed Jul 6, 2016
1 parent 08db254 commit e76e8ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/widgets/search-box/__tests__/search-box-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ describe('searchBox()', () => {
beforeEach(() => {
container = document.body.appendChild(document.createElement('input'));
container.focus = sinon.spy();
container.setSelectionRange = sinon.spy();
});

context('when auto', () => {
Expand Down Expand Up @@ -615,6 +616,15 @@ describe('searchBox()', () => {
// Then
expect(container.focus.called).toEqual(true);
});

it('forces cursor to be at the end of the query', () => {
// Given
helper.state.query = 'foo';
// When
widget.init({state, helper, onHistoryChange});
// Then
expect(container.setSelectionRange.calledWith(3, 3)).toEqual(true);
});
});

context('when false', () => {
Expand Down
1 change: 1 addition & 0 deletions src/widgets/search-box/search-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ function searchBox({

if (autofocus === true || autofocus === 'auto' && helper.state.query === '') {
input.focus();
input.setSelectionRange(helper.state.query.length, helper.state.query.length);
}
},
render({helper}) {
Expand Down

0 comments on commit e76e8ce

Please sign in to comment.