@@ -248,6 +248,48 @@ uis.directive('uiSelect',
248
248
element [ 0 ] . style . top = '' ;
249
249
element [ 0 ] . style . width = originalWidth ;
250
250
}
251
+
252
+ // Hold on to a reference to the .ui-select-dropdown element for direction support.
253
+ var dropdown = null ,
254
+ directionUpClassName = 'direction-up' ;
255
+
256
+ // Support changing the direction of the dropdown if there isn't enough space to render it.
257
+ scope . $watch ( '$select.open' , function ( isOpen ) {
258
+ if ( isOpen ) {
259
+ dropdown = angular . element ( element ) . querySelectorAll ( '.ui-select-dropdown' ) ;
260
+ if ( dropdown === null ) {
261
+ return ;
262
+ }
263
+
264
+ // Hide the dropdown so there is no flicker until $timeout is done executing.
265
+ dropdown [ 0 ] . style . visibility = 'hidden' ;
266
+
267
+ // Delay positioning the dropdown until all choices have been added so its height is correct.
268
+ $timeout ( function ( ) {
269
+ var offset = uisOffset ( element ) ;
270
+ var offsetDropdown = uisOffset ( dropdown ) ;
271
+
272
+ // Determine if the direction of the dropdown needs to be changed.
273
+ if ( offset . top + offset . height + offsetDropdown . height > $document [ 0 ] . documentElement . scrollTop + $document [ 0 ] . documentElement . clientHeight ) {
274
+ dropdown [ 0 ] . style . position = 'absolute' ;
275
+ dropdown [ 0 ] . style . top = ( offsetDropdown . height * - 1 ) + 'px' ;
276
+ element . addClass ( directionUpClassName ) ;
277
+ }
278
+
279
+ // Display the dropdown once it has been positioned.
280
+ dropdown [ 0 ] . style . visibility = '' ;
281
+ } ) ;
282
+ } else {
283
+ if ( dropdown === null ) {
284
+ return ;
285
+ }
286
+
287
+ // Reset the position of the dropdown.
288
+ dropdown [ 0 ] . style . position = '' ;
289
+ dropdown [ 0 ] . style . top = '' ;
290
+ element . removeClass ( directionUpClassName ) ;
291
+ }
292
+ } ) ;
251
293
} ;
252
294
}
253
295
} ;
0 commit comments