@@ -257,8 +257,12 @@ uis.directive('uiSelect',
257257 directionUpClassName = 'direction-up' ;
258258
259259 // Support changing the direction of the dropdown if there isn't enough space to render it.
260- scope . $watch ( '$select.open' , function ( isOpen ) {
261- if ( isOpen ) {
260+ scope . $watch ( '$select.open' , function ( ) {
261+ scope . calculateDropdownPos ( ) ;
262+ } ) ;
263+
264+ scope . calculateDropdownPos = function ( ) {
265+ if ( $select . open ) {
262266 dropdown = angular . element ( element ) . querySelectorAll ( '.ui-select-dropdown' ) ;
263267 if ( dropdown . length === 0 ) {
264268 return ;
@@ -269,14 +273,25 @@ uis.directive('uiSelect',
269273
270274 // Delay positioning the dropdown until all choices have been added so its height is correct.
271275 $timeout ( function ( ) {
276+
277+ element . removeClass ( directionUpClassName ) ;
278+
272279 var offset = uisOffset ( element ) ;
273280 var offsetDropdown = uisOffset ( dropdown ) ;
274281
282+ //https://code.google.com/p/chromium/issues/detail?id=342307#c4
283+ var scrollTop = $document [ 0 ] . documentElement . scrollTop || $document [ 0 ] . body . scrollTop ; //To make it cross browser (blink, webkit, IE, Firefox).
284+
275285 // Determine if the direction of the dropdown needs to be changed.
276- if ( offset . top + offset . height + offsetDropdown . height > $document [ 0 ] . documentElement . scrollTop + $document [ 0 ] . documentElement . clientHeight ) {
286+ if ( offset . top + offset . height + offsetDropdown . height > scrollTop + $document [ 0 ] . documentElement . clientHeight ) {
287+ //Go UP
277288 dropdown [ 0 ] . style . position = 'absolute' ;
278289 dropdown [ 0 ] . style . top = ( offsetDropdown . height * - 1 ) + 'px' ;
279290 element . addClass ( directionUpClassName ) ;
291+ } else {
292+ //Go DOWN
293+ dropdown [ 0 ] . style . position = '' ;
294+ dropdown [ 0 ] . style . top = '' ;
280295 }
281296
282297 // Display the dropdown once it has been positioned.
@@ -292,7 +307,7 @@ uis.directive('uiSelect',
292307 dropdown [ 0 ] . style . top = '' ;
293308 element . removeClass ( directionUpClassName ) ;
294309 }
295- } ) ;
310+ } ;
296311 } ;
297312 }
298313 } ;
0 commit comments