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

Commit 8c4d1bf

Browse files
committed
Merge pull request #1595 from darrinholst/1593-position-up
fix(positioning): wait for animation to complete
2 parents f39b868 + ca4d09e commit 8c4d1bf

File tree

1 file changed

+50
-37
lines changed

1 file changed

+50
-37
lines changed

src/uiSelectDirective.js

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -328,57 +328,70 @@ uis.directive('uiSelect',
328328

329329
};
330330

331-
scope.calculateDropdownPos = function(){
331+
var calculateDropdownPosAfterAnimation = function() {
332+
// Delay positioning the dropdown until all choices have been added so its height is correct.
333+
$timeout(function() {
334+
if ($select.dropdownPosition === 'up') {
335+
//Go UP
336+
setDropdownPosUp();
337+
} else {
338+
//AUTO
339+
element.removeClass(directionUpClassName);
340+
341+
var offset = uisOffset(element);
342+
var offsetDropdown = uisOffset(dropdown);
343+
344+
//https://code.google.com/p/chromium/issues/detail?id=342307#c4
345+
var scrollTop = $document[0].documentElement.scrollTop || $document[0].body.scrollTop; //To make it cross browser (blink, webkit, IE, Firefox).
346+
347+
// Determine if the direction of the dropdown needs to be changed.
348+
if (offset.top + offset.height + offsetDropdown.height > scrollTop + $document[0].documentElement.clientHeight) {
349+
//Go UP
350+
setDropdownPosUp(offset, offsetDropdown);
351+
}else{
352+
//Go DOWN
353+
setDropdownPosDown(offset, offsetDropdown);
354+
}
355+
}
332356

357+
// Display the dropdown once it has been positioned.
358+
dropdown[0].style.opacity = 1;
359+
});
360+
};
361+
362+
scope.calculateDropdownPos = function() {
333363
if ($select.open) {
334364
dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown');
365+
335366
if (dropdown.length === 0) {
336367
return;
337368
}
338369

339370
// Hide the dropdown so there is no flicker until $timeout is done executing.
340371
dropdown[0].style.opacity = 0;
341372

342-
// Delay positioning the dropdown until all choices have been added so its height is correct.
343-
$timeout(function(){
344-
345-
if ($select.dropdownPosition === 'up'){
346-
//Go UP
347-
setDropdownPosUp();
348-
349-
}else{ //AUTO
350-
351-
element.removeClass(directionUpClassName);
373+
if (!uisOffset(dropdown).height && $select.$animate && $select.$animate.on && $select.$animate.enabled(dropdown)) {
374+
var needsCalculated = true;
352375

353-
var offset = uisOffset(element);
354-
var offsetDropdown = uisOffset(dropdown);
355-
356-
//https://code.google.com/p/chromium/issues/detail?id=342307#c4
357-
var scrollTop = $document[0].documentElement.scrollTop || $document[0].body.scrollTop; //To make it cross browser (blink, webkit, IE, Firefox).
358-
359-
// Determine if the direction of the dropdown needs to be changed.
360-
if (offset.top + offset.height + offsetDropdown.height > scrollTop + $document[0].documentElement.clientHeight) {
361-
//Go UP
362-
setDropdownPosUp(offset, offsetDropdown);
363-
}else{
364-
//Go DOWN
365-
setDropdownPosDown(offset, offsetDropdown);
376+
$select.$animate.on('enter', dropdown, function (elem, phase) {
377+
if (phase === 'close' && needsCalculated) {
378+
calculateDropdownPosAfterAnimation();
379+
needsCalculated = false;
366380
}
367-
368-
}
369-
370-
// Display the dropdown once it has been positioned.
371-
dropdown[0].style.opacity = 1;
372-
});
381+
});
382+
} else {
383+
calculateDropdownPosAfterAnimation();
384+
}
373385
} else {
374-
if (dropdown === null || dropdown.length === 0) {
375-
return;
376-
}
386+
if (dropdown === null || dropdown.length === 0) {
387+
return;
388+
}
377389

378-
// Reset the position of the dropdown.
379-
dropdown[0].style.position = '';
380-
dropdown[0].style.top = '';
381-
element.removeClass(directionUpClassName);
390+
// Reset the position of the dropdown.
391+
dropdown[0].style.opacity = 0;
392+
dropdown[0].style.position = '';
393+
dropdown[0].style.top = '';
394+
element.removeClass(directionUpClassName);
382395
}
383396
};
384397
};

0 commit comments

Comments
 (0)