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

Commit 45dd9be

Browse files
chrisirhcpkozlowski-opensource
authored andcommitted
fix(typeahead): highlight return match if no query
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.
1 parent 87b4aa7 commit 45dd9be

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/typeahead/test/typeahead-highlight.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ describe('typeaheadHighlight', function () {
2323
expect(highlightFilter('before match after', 'nomatch')).toEqual('before match after');
2424
});
2525

26+
it('should do nothing if no or empty query', function () {
27+
expect(highlightFilter('before match after', '')).toEqual('before match after');
28+
expect(highlightFilter('before match after', null)).toEqual('before match after');
29+
expect(highlightFilter('before match after', undefined)).toEqual('before match after');
30+
});
31+
2632
it('issue 316 - should work correctly for regexp reserved words', function () {
2733
expect(highlightFilter('before (match after', '(match')).toEqual('before <strong>(match</strong> after');
2834
});

src/typeahead/typeahead.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,6 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
313313
}
314314

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

0 commit comments

Comments
 (0)