@@ -366,32 +366,35 @@ uis.controller('uiSelectCtrl',
366366 return ctrl . placeholder ;
367367 } ;
368368
369- var containerSizeWatch ;
370- ctrl . sizeSearchInput = function ( ) {
369+ var sizeWatch = null ;
370+ ctrl . sizeSearchInput = function ( ) {
371371 var input = _searchInput [ 0 ] ,
372- container = _searchInput . parent ( ) . parent ( ) [ 0 ] ;
373- _searchInput . css ( 'width' , '10px' ) ;
374- var calculate = function ( ) {
375- var newWidth = container . clientWidth - input . offsetLeft - 10 ;
376- if ( newWidth < 50 ) newWidth = container . clientWidth ;
377- _searchInput . css ( 'width' , newWidth + 'px' ) ;
378- } ;
379- $timeout ( function ( ) { //Give tags time to render correctly
380- if ( ( container . clientWidth === 0 || input . offsetParent === null ) && ! containerSizeWatch ) {
381- containerSizeWatch = $scope . $watchGroup ( [
382- function ( ) { return container . clientWidth ; } ,
383- function ( ) { return input . offsetParent ; }
384- ] , function ( newValues ) {
385- if ( newValues [ 0 ] !== 0 && newValues [ 1 ] !== null ) {
386- calculate ( ) ;
387- containerSizeWatch ( ) ;
388- containerSizeWatch = null ;
372+ container = _searchInput . parent ( ) . parent ( ) [ 0 ] ,
373+ calculateContainerWidth = function ( ) {
374+ // Return the container width only if the search input is visible
375+ return container . clientWidth * ! ! input . offsetParent ;
376+ } ,
377+ updateIfVisible = function ( containerWidth ) {
378+ if ( containerWidth === 0 ) {
379+ return false ;
380+ }
381+ var inputWidth = containerWidth - input . offsetLeft - 10 ;
382+ if ( inputWidth < 50 ) inputWidth = containerWidth ;
383+ _searchInput . css ( 'width' , inputWidth + 'px' ) ;
384+ return true ;
385+ } ;
386+
387+ _searchInput . css ( 'width' , '10px' ) ;
388+ $timeout ( function ( ) { //Give tags time to render correctly
389+ if ( sizeWatch === null && ! updateIfVisible ( calculateContainerWidth ( ) ) ) {
390+ sizeWatch = $scope . $watch ( calculateContainerWidth , function ( containerWidth ) {
391+ if ( updateIfVisible ( containerWidth ) ) {
392+ sizeWatch ( ) ;
393+ sizeWatch = null ;
389394 }
390395 } ) ;
391- } else if ( ! containerSizeWatch ) {
392- calculate ( ) ;
393396 }
394- } , 0 , false ) ;
397+ } ) ;
395398 } ;
396399
397400 function _handleDropDownSelection ( key ) {
0 commit comments