Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(typeahead): highlight return match if no query
Browse files Browse the repository at this point in the history
This makes the highlighter behave more consistently like other filters.

It also makes it more useful as an empty query doesn't result in an
empty result.
  • Loading branch information
chrisirhc authored and pkozlowski-opensource committed Aug 27, 2013
1 parent 87b4aa7 commit 45dd9be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/typeahead/test/typeahead-highlight.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ describe('typeaheadHighlight', function () {
expect(highlightFilter('before match after', 'nomatch')).toEqual('before match after');
});

it('should do nothing if no or empty query', function () {
expect(highlightFilter('before match after', '')).toEqual('before match after');
expect(highlightFilter('before match after', null)).toEqual('before match after');
expect(highlightFilter('before match after', undefined)).toEqual('before match after');
});

it('issue 316 - should work correctly for regexp reserved words', function () {
expect(highlightFilter('before (match after', '(match')).toEqual('before <strong>(match</strong> after');
});
Expand Down
2 changes: 1 addition & 1 deletion src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,6 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
}

return function(matchItem, query) {
return query ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '<strong>$&</strong>') : query;
return query ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '<strong>$&</strong>') : matchItem;
};
});

0 comments on commit 45dd9be

Please sign in to comment.