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
…1123)

fixes #946
  • Loading branch information
vvo authored Jul 8, 2016
1 parent 0710af0 commit 8a27769
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

1 comment on commit 8a27769

@powtac
Copy link

@powtac powtac commented on 8a27769 Jul 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.