Material: autocomplete: Wrong height is set for md-virtual-repeat-container

Created on 13 Jan 2016  路  12Comments  路  Source: angular/material

Hi,

When focusing on an autocomplete field, sometimes the rendered suggestion list is shrunk to show only one item, whereas there are more items on the list. This happens quite randomly, sometimes more often than this particular demo (gif):

autocomplete-bug

I tried to debug this, but led to no results unfortunately. Here is my findings (sorry if it doesn't help much):

Setting a new height is triggered at VirtualRepeatController.prototype.containerUpdated when virtualRepeatUpdate_ method is called. The problem, I think, arises when the items (referred to the list of suggestions) sent to this method is an empty array.

Moreover, when the items array is correct, through the chain calls, at VirtualRepeatContainerController.prototype.autoShrink_, setSize_ method is never called, which seem to solve the problem if it did.

minor fixed

Most helpful comment

As a workaround- adding this into your getSuggestions function seems to work

this.timeout_(function() {
  var outerContainer = document.querySelector('.md-autocomplete-suggestions-container');
  var innerContainer = document.querySelector('.md-virtual-repeat-sizer');
  outerContainer.style.height = innerContainer.style.height;
});

All 12 comments

You can reproduce this for certain if you were to scroll to get an option and then try to open the list again.

demo

This is the same issue I think-
http://codepen.io/anon/pen/LGzxyK

In the input box, hit backspace twice. You'll see the new height isn't recalculated properly.

image

As a workaround- adding this into your getSuggestions function seems to work

this.timeout_(function() {
  var outerContainer = document.querySelector('.md-autocomplete-suggestions-container');
  var innerContainer = document.querySelector('.md-virtual-repeat-sizer');
  outerContainer.style.height = innerContainer.style.height;
});

:+1:

+1

This seems to be related to #5611

It's still happening in 1.1.1

+1

Still happening.. not sure why these features are "offered" in the documentation when their basic use case functionalities are broken..

@gbaj Your suggestion worked perfectly for me.
In my case I retrieved the element containers via link and made them available via scope to my directives controller.
When my onBlur ran, I did an if check and if the suggestionContainer height was 0 I simply updated it to match the virtualRepeaterContainers height which always seemed to persist.

In my case, I identified and made available via scope in link as follows:

var suggestionsContainer = angular.element(element).find('.md-autocomplete-suggestions-container');
var virtualRepeaterContainer = angular.element(element).find('.md-virtual-repeat-sizer');

scope.suggestionsContainer = suggestionsContainer;
scope.virtualRepeaterContainer = virtualRepeaterContainer;

Then, in my directives controller during my onBlur event:

$timeout(function() {
    if ($scope.suggestionsContainer[0].style.height === '0px') {
        $scope.suggestionsContainer[0].style.height = '528px';
    }
}, 2000);

This is still around, although I've noticed for my particular use case it was only triggering the wrong height when the list was temporarily empty, and "md-not-found" was used. When removing md-not-found I could no longer trigger a bad height. This is possibly related to being called from a remote service.

This appears to be fixed in 1.1.0 and seems to still be working properly in 1.1.7. Here's an updated CodePen for 1.1.0.

If you are seeing a similar problem against 1.1.7, please open a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rdantonio picture rdantonio  路  3Comments

robertmesserle picture robertmesserle  路  3Comments

ghost picture ghost  路  3Comments

Dona278 picture Dona278  路  3Comments

chriseyhorn picture chriseyhorn  路  3Comments