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

Commit 29ce97d

Browse files
committed
Recalculate dropdown position when search changes
1 parent 9101742 commit 29ce97d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/uiSelectController.js

Lines changed: 1 addition & 0 deletions
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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ uis.directive('uiSelect',
258258

259259
// Support changing the direction of the dropdown if there isn't enough space to render it.
260260
scope.$watch('$select.open', function(isOpen) {
261-
if (isOpen) {
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 === null) {
264268
return;
@@ -269,6 +273,9 @@ 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

@@ -277,9 +284,14 @@ uis.directive('uiSelect',
277284

278285
// Determine if the direction of the dropdown needs to be changed.
279286
if (offset.top + offset.height + offsetDropdown.height > scrollTop + $document[0].documentElement.clientHeight) {
287+
//Go UP
280288
dropdown[0].style.position = 'absolute';
281289
dropdown[0].style.top = (offsetDropdown.height * -1) + 'px';
282290
element.addClass(directionUpClassName);
291+
}else{
292+
//Go DOWN
293+
dropdown[0].style.position = '';
294+
dropdown[0].style.top = '';
283295
}
284296

285297
// Display the dropdown once it has been positioned.
@@ -295,7 +307,7 @@ uis.directive('uiSelect',
295307
dropdown[0].style.top = '';
296308
element.removeClass(directionUpClassName);
297309
}
298-
});
310+
};
299311
};
300312
}
301313
};

0 commit comments

Comments
 (0)