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

Commit

Permalink
feat(autocomplete): dropdown will now stretch to accomodate longer text
Browse files Browse the repository at this point in the history
Size logic is smart enough to find the maximum possible size based on either left or right horizontal snapping.  If the content is larger than this, it will use an ellipsis overflow by default.
  • Loading branch information
Robert Messerle committed Apr 8, 2015
1 parent fbed048 commit b134370
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/components/autocomplete/autocomplete.scss
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ md-autocomplete {
}
.md-autocomplete-suggestions {
position: absolute;
top: 100%;
left: 0;
right: 0;
box-shadow: 0 2px 5px rgba(black, 0.25);
margin: 0;
list-style: none;
Expand All @@ -190,6 +187,8 @@ md-autocomplete {
transition: background 0.15s linear;
cursor: pointer;
margin: 0;
white-space: nowrap;
text-overflow: ellipsis;
&.ng-enter,
&.ng-hide-remove {
transition: none;
Expand Down
17 changes: 16 additions & 1 deletion src/components/autocomplete/js/autocompleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@
bot = root.height - vrect.top,
left = hrect.left - root.left,
width = hrect.width,
styles = { left: left + 'px', width: width + 'px' };
styles = {
left: left + 'px',
minWidth: width + 'px',
maxWidth: Math.max(hrect.right - root.left, root.right - hrect.left) - MENU_PADDING + 'px',
opacity: 0
};
if (top > bot && root.height - hrect.bottom - MENU_PADDING < MAX_HEIGHT) {
styles.top = 'auto';
styles.bottom = bot + 'px';
Expand All @@ -81,7 +86,17 @@
styles.bottom = 'auto';
styles.maxHeight = Math.min(MAX_HEIGHT, root.height - hrect.bottom - MENU_PADDING) + 'px';
}
$timeout(correctHorizontalAlignment, 0, false);
elements.$.ul.css(styles);

function correctHorizontalAlignment () {
var dropdown = elements.ul.getBoundingClientRect(),
styles = { opacity: 1 };
if (dropdown.right > root.right - MENU_PADDING) {
styles.left = (hrect.right - dropdown.width) + 'px';
}
elements.$.ul.css(styles);
}
}

function moveDropdown () {
Expand Down

0 comments on commit b134370

Please sign in to comment.