Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 15920e4

Browse files
committed
Merge pull request #1212 from angular-ui/fix-dropdown-pos
fix(dropdown): cross browser dropdown position
2 parents e817c5d + f98b050 commit 15920e4

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/uiSelectController.js

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ uis.controller('uiSelectCtrl',
142142
ctrl.itemProperty = ctrl.parserResult.itemName;
143143

144144
ctrl.refreshItems = function (data){
145+
$scope.calculateDropdownPos();
145146
data = data || ctrl.parserResult.source($scope);
146147
var selectedItems = ctrl.selected;
147148
//TODO should implement for single mode removeSelected

src/uiSelectDirective.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)