Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit ae00a7f

Browse files
author
Robert Messerle
committed
fix(autocomplete): adjusts vertical offset of dropdown to account for ngMessages in floating label examples
1 parent c4f68a8 commit ae00a7f

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/components/autocomplete/js/autocompleteController.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
8383
bot = root.bottom - vrect.top,
8484
left = hrect.left - root.left,
8585
width = hrect.width,
86+
offset = getVerticalOffset(),
8687
styles = {
8788
left: left + 'px',
8889
minWidth: width + 'px',
@@ -93,14 +94,30 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
9394
styles.bottom = bot + 'px';
9495
styles.maxHeight = Math.min(MAX_HEIGHT, hrect.top - root.top - MENU_PADDING) + 'px';
9596
} else {
96-
styles.top = top + 'px';
97+
styles.top = (top - offset) + 'px';
9798
styles.bottom = 'auto';
9899
styles.maxHeight = Math.min(MAX_HEIGHT, root.bottom - hrect.bottom - MENU_PADDING) + 'px';
99100
}
100101

101102
elements.$.scrollContainer.css(styles);
102103
$mdUtil.nextTick(correctHorizontalAlignment, false);
103104

105+
/**
106+
* Calculates the vertical offset for floating label examples to account for ngMessages
107+
* @returns {number}
108+
*/
109+
function getVerticalOffset () {
110+
var offset = 0;
111+
var inputContainer = $element.find('md-input-container');
112+
if (inputContainer.length) {
113+
var input = inputContainer.find('input');
114+
offset = inputContainer.prop('offsetHeight');
115+
offset -= input.prop('offsetTop');
116+
offset -= input.prop('offsetHeight');
117+
}
118+
return offset;
119+
}
120+
104121
/**
105122
* Makes sure that the menu doesn't go off of the screen on either side.
106123
*/
@@ -347,11 +364,12 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
347364
}
348365
}
349366

367+
/**
368+
* Force blur on input element
369+
* @param forceBlur
370+
*/
350371
function doBlur(forceBlur) {
351-
if (forceBlur) {
352-
noBlur = false;
353-
}
354-
372+
if (forceBlur) noBlur = false;
355373
elements.input.blur();
356374
}
357375

0 commit comments

Comments
 (0)