Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ var uis = angular.module('ui.select', [])
}

return function(matchItem, query) {
return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '<span class="ui-select-highlight">$&</span>') : matchItem;
return query && matchItem ? ('' + matchItem).replace(new RegExp(escapeRegexp(query), 'gi'), '<span class="ui-select-highlight">$&</span>') : matchItem;
};
})

Expand Down
29 changes: 29 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2254,4 +2254,33 @@ describe('ui-select tests', function() {
});
});

describe('highlight filter', function() {
var highlight;

beforeEach(function() {
highlight = $injector.get('highlightFilter');
});

it('returns the item if there is no match', function() {
var query = 'January';
var item = 'December';

expect(highlight(item, query)).toBe('December');
});

it('wraps search strings matches in ui-select-highlight class', function() {
var query = 'er';
var item = 'December';

expect(highlight(item, query)).toBe('Decemb<span class="ui-select-highlight">er</span>');
});

it('properly highlights numeric items', function() {
var query = '15';
var item = 2015;

expect(highlight(item, query)).toBe('20<span class="ui-select-highlight">15</span>');
});
});

});