Skip to content

Commit

Permalink
on up/down arrow, set the input only if data.val is a string
Browse files Browse the repository at this point in the history
don't want to set it to [Object object] or redo search
  • Loading branch information
kielni committed May 7, 2018
1 parent 7c8aa88 commit 196fad8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,11 @@ var Typeahead = (function() {

// cursor moved to different selectable
if (data) {
this.input.setInputValue(data.val);
// set the input only if data.val is a string
// don't want to set it to [Object object]
if (typeof data.val === 'string') {
this.input.setInputValue(data.val);
}
}

// cursor moved off of selectables, back to input
Expand Down
9 changes: 9 additions & 0 deletions test/typeahead/typeahead_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Typeahead', function() {
this.$input = $fixture.find('input');

testData = { dataset: 'bar', val: 'foo bar', obj: 'fiz' };
testObjectData = { dataset: 'bar', val: { id: 1, name: 'foo bar' }, obj: { id: 1, name: 'foo bar' } };

this.view = new Typeahead({
input: new Input(),
Expand Down Expand Up @@ -1383,6 +1384,14 @@ describe('Typeahead', function() {
expect(this.input.setInputValue).toHaveBeenCalledWith(testData.val);
});

it('should not update the input value if moved to object selectable', function() {
this.menu.getSelectableData.andReturn(testObjectData);
this.menu.selectableRelativeToCursor.andReturn($());

this.view.moveCursor(1);
expect(this.input.setInputValue).not.toHaveBeenCalled();
});

it('should reset the input value if moved to input', function() {
this.menu.selectableRelativeToCursor.andReturn($());
this.view.moveCursor(1);
Expand Down

0 comments on commit 196fad8

Please sign in to comment.