@@ -366,29 +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 && ! containerSizeWatch ) {
381- containerSizeWatch = $scope . $watch ( function ( ) { return container . clientWidth ; } , function ( newValue ) {
382- if ( newValue !== 0 ) {
383- calculate ( ) ;
384- containerSizeWatch ( ) ;
385- 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 ;
386394 }
387395 } ) ;
388- } else if ( ! containerSizeWatch ) {
389- calculate ( ) ;
390396 }
391- } , 0 , false ) ;
397+ } ) ;
392398 } ;
393399
394400 function _handleDropDownSelection ( key ) {
0 commit comments