From 97893fa3b7b214c295ce000ff59fe6d8aab8533a Mon Sep 17 00:00:00 2001 From: Chuan-Jhe Hwong Date: Tue, 22 May 2018 15:50:25 +0800 Subject: [PATCH] feat(uiSelectDirective): calculate dropdown position left Make dropdown menu align to the bottom-right edge of its select area if the dropdown menu is out of visible area of the browser --- src/uiSelectDirective.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index e1e8e0a89..98e8807ab 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -368,6 +368,14 @@ uis.directive('uiSelect', }; + var setDropdownPosLeft = function(offset, offsetDropdown) { + + var droppdownPosLeft = offsetDropdown.width - offset.width; + dropdown[0].style.position = 'absolute'; + dropdown[0].style.left = -droppdownPosLeft + 'px'; + + }; + var calculateDropdownPosAfterAnimation = function() { // Delay positioning the dropdown until all choices have been added so its height is correct. $timeout(function() { @@ -392,6 +400,11 @@ uis.directive('uiSelect', //Go DOWN setDropdownPosDown(offset, offsetDropdown); } + var offsetLeft = offset.left + offsetDropdown.width; + var documentWidth = $document[0].documentElement.offsetWidth; + if (offsetLeft > documentWidth) { + setDropdownPosLeft(offset, offsetDropdown); + } } // Display the dropdown once it has been positioned. @@ -443,3 +456,4 @@ uis.directive('uiSelect', } }; }]); +