File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ var uis = angular.module('ui.select', [])
133
133
}
134
134
135
135
return function ( matchItem , query ) {
136
- return query && matchItem ? matchItem . replace ( new RegExp ( escapeRegexp ( query ) , 'gi' ) , '<span class="ui-select-highlight">$&</span>' ) : matchItem ;
136
+ return query && matchItem ? ( '' + matchItem ) . replace ( new RegExp ( escapeRegexp ( query ) , 'gi' ) , '<span class="ui-select-highlight">$&</span>' ) : matchItem ;
137
137
} ;
138
138
} )
139
139
Original file line number Diff line number Diff line change @@ -2254,4 +2254,33 @@ describe('ui-select tests', function() {
2254
2254
} ) ;
2255
2255
} ) ;
2256
2256
2257
+ describe ( 'highlight filter' , function ( ) {
2258
+ var highlight ;
2259
+
2260
+ beforeEach ( function ( ) {
2261
+ highlight = $injector . get ( 'highlightFilter' ) ;
2262
+ } ) ;
2263
+
2264
+ it ( 'returns the item if there is no match' , function ( ) {
2265
+ var query = 'January' ;
2266
+ var item = 'December' ;
2267
+
2268
+ expect ( highlight ( item , query ) ) . toBe ( 'December' ) ;
2269
+ } ) ;
2270
+
2271
+ it ( 'wraps search strings matches in ui-select-highlight class' , function ( ) {
2272
+ var query = 'er' ;
2273
+ var item = 'December' ;
2274
+
2275
+ expect ( highlight ( item , query ) ) . toBe ( 'Decemb<span class="ui-select-highlight">er</span>' ) ;
2276
+ } ) ;
2277
+
2278
+ it ( 'properly highlights numeric items' , function ( ) {
2279
+ var query = '15' ;
2280
+ var item = 2015 ;
2281
+
2282
+ expect ( highlight ( item , query ) ) . toBe ( '20<span class="ui-select-highlight">15</span>' ) ;
2283
+ } ) ;
2284
+ } ) ;
2285
+
2257
2286
} ) ;
You can’t perform that action at this time.
0 commit comments