This repository was archived by the owner on Oct 2, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 388
388
return ctrl . placeholder ;
389
389
} ;
390
390
391
+ var containerSizeWatch ;
391
392
ctrl . sizeSearchInput = function ( ) {
392
393
var input = _searchInput [ 0 ] ,
393
394
container = _searchInput . parent ( ) . parent ( ) [ 0 ] ;
394
395
_searchInput . css ( 'width' , '10px' ) ;
395
- $timeout ( function ( ) {
396
+ var calculate = function ( ) {
396
397
var newWidth = container . clientWidth - input . offsetLeft - 10 ;
397
398
if ( newWidth < 50 ) newWidth = container . clientWidth ;
398
399
_searchInput . css ( 'width' , newWidth + 'px' ) ;
400
+ } ;
401
+ $timeout ( function ( ) { //Give tags time to render correctly
402
+ if ( container . clientWidth === 0 && ! containerSizeWatch ) {
403
+ containerSizeWatch = $scope . $watch ( function ( ) { return container . clientWidth ; } , function ( newValue ) {
404
+ if ( newValue !== 0 ) {
405
+ calculate ( ) ;
406
+ containerSizeWatch ( ) ;
407
+ containerSizeWatch = null ;
408
+ }
409
+ } ) ;
410
+ } else if ( ! containerSizeWatch ) {
411
+ calculate ( ) ;
412
+ }
399
413
} , 0 , false ) ;
400
414
} ;
401
415
919
933
} ) ;
920
934
921
935
if ( $select . multiple ) {
922
- $select . sizeSearchInput ( ) ;
936
+ $select . sizeSearchInput ( ) ;
923
937
}
924
938
925
939
}
Original file line number Diff line number Diff line change @@ -1083,12 +1083,14 @@ describe('ui-select tests', function() {
1083
1083
it ( 'should update size of search input after removing an item' , function ( ) {
1084
1084
scope . selection . selectedMultiple = [ scope . people [ 4 ] , scope . people [ 5 ] ] ; //Wladimir & Samantha
1085
1085
var el = createUiSelectMultiple ( ) ;
1086
+
1087
+ spyOn ( el . scope ( ) . $select , 'sizeSearchInput' ) ;
1088
+
1086
1089
var searchInput = el . find ( '.ui-select-search' ) ;
1087
1090
var oldWidth = searchInput . css ( 'width' ) ;
1088
- el . find ( '.ui-select-match-item' ) . first ( ) . find ( '.ui-select-match-close' ) . click ( ) ;
1089
1091
1090
- $timeout . flush ( ) ;
1091
- expect ( oldWidth ) . not . toBe ( searchInput . css ( 'width' ) ) ;
1092
+ el . find ( '.ui-select-match-item' ) . first ( ) . find ( '.ui-select-match-close' ) . click ( ) ;
1093
+ expect ( el . scope ( ) . $select . sizeSearchInput ) . toHaveBeenCalled ( ) ;
1092
1094
1093
1095
} ) ;
1094
1096
You can’t perform that action at this time.
0 commit comments