material icon indicating copy to clipboard operation
material copied to clipboard

Autocomplete dropdown is too narrow when inside of md-chips

Open mxab opened this issue 11 years ago • 40 comments

Hi,

if I use a autocomplete in a chips the dropdown items are too short, is there any way to influence the dropdown's width? screen shot 2015-09-03 at 11 22 55

http://codepen.io/mxab/pen/xwbZBL?editors=101

mxab avatar Sep 03 '15 09:09 mxab

same here. 0.10.1 and 0.11.0-rc1

nextor2k avatar Sep 03 '15 18:09 nextor2k

I was looking into this the other day but didn't have time to figure out why the CSS wasn't working like it should, as the inner items are the correct size. If either of you have a moment to dig in, some more information about exactly why the width is off would be very much appreciated.

topherfangio avatar Sep 03 '15 20:09 topherfangio

the width is set in directive programmatically.

nextor2k avatar Sep 03 '15 20:09 nextor2k

@nestorneto From what I was seeing, the min-width/max-width was set programmatically, but not the actual width. Are you seeing the actual width property being set?

topherfangio avatar Sep 03 '15 21:09 topherfangio

it didnt set width. maybe its the problem. the component assumes the min-width

nextor2k avatar Sep 03 '15 21:09 nextor2k

@nestorneto That's the part I couldn't figure out. Just setting min/max shouldn't actually affect it at all, it should still be sizing to the items contents as long as it's between min/max. I think there is an odd CSS interaction going on here. We'll try to track it down.

topherfangio avatar Sep 03 '15 21:09 topherfangio

This is what's causing the items to be 16px not as wide (if you set it to 0 it will fill the whole area):

.md-virtual-repeat-container .md-virtual-repeat-offsetter {
 .....
right: 16px;
... }

There is also the "sizer" which is causing the scrollbars, if you take it out the scrollbars go away, but I am sure it has a use :)

<div class="md-virtual-repeat-sizer" style="height: 48px;"></div>

It would be great if you could also fix the height of the dropdown when there are no matches - it defaults to 226 px because the resizing does not execute if there are no items:

VirtualRepeatController.prototype.containerUpdated = function() { 
  // If itemSize is unknown, attempt to measure it.
    if (!this.itemSize) {
    this.unwatchItemSize_ = this.$scope.$watchCollection(
        this.repeatListExpression,
        angular.bind(this, function(items) {
          if (items && items.length) {
            this.$$rAF(angular.bind(this, this.readItemSize_));
          }

Finally, this is not really related to these issues, but is there a way to add a link or a button in the md-not-found template? I tried both but the click event doesn't get fired, or perhaps it is intended to work this way? Thanks!

paulflo150 avatar Sep 04 '15 02:09 paulflo150

+1

r0b- avatar Sep 15 '15 19:09 r0b-

+1

webley avatar Sep 17 '15 13:09 webley

I would love to have this fixed in 0.11.1 since it's a bug introduced in 0.11. It's breaking for our application. For us priority is more then medium.

lievenjanssen avatar Sep 25 '15 16:09 lievenjanssen

+1 to increase priority - a lot of our users reported about it :(

tirana avatar Oct 13 '15 16:10 tirana

So, I think I finally figured out the real reason this is happening: the autocomplete was updated in 0.11 to use the virtual repeat for performance reasons. Part of this change also updated the autocomplete dropdown to set it's size based on the autocomplete's input size.

So, a quick & dirty workaround is to set the size of the input in your CSS:

.md-chips .md-chip-input-container md-autocomplete input {
    width: 400px;
}

This should make the autocomplete the right size and still provides a decent experience; however, I think the proper fix would be to figure out why the autocomplete manually sets this, and perhaps give users more control.

@r0b- @lievenjanssen @tirana Can you guys give this a try and provide some feedback on whether or not this workaround helps, or if your particular use-cases require a different solution?

topherfangio avatar Oct 13 '15 17:10 topherfangio

yes. it works! thanks!

tirana avatar Oct 13 '15 17:10 tirana

Thanks for finding the workaround - it's working well for me.

webley avatar Oct 14 '15 11:10 webley

Hmmm, I have a responsive site that needs different widths depending on the screen size. If I set the width by css breakpoints the container width is changed but the virtual repeat seems to work with the old item heights and things get messed up if the text wraps and item height changes..

Is there a way to let the virtual repeat recalculate or sth like that?

r0b- avatar Oct 18 '15 07:10 r0b-

+1

Same as @r0b- here. Different autocomplete widths, but for now I can add some classes, set diffenret widths and hope page isn't risized hehe

brenovieira avatar Oct 23 '15 04:10 brenovieira

+1

humancatfood avatar Dec 09 '15 17:12 humancatfood

I agree and am confused with this issue. I also discovered that the actual width of the dropdown menu (the md-virtual-repeat-container and all child elements) is set by the min-width value on the md-virtual-repeat container element, rather than expanding to a width that is between min-width and max-width and that also expands to display the full length of all the content of all the child elements. Also interesting, when you set the min-width to "0 !important" via CSS, thereby restoring the default value, it will override the programmatically established min-width on the md-virtual-repeat-container element, but the md-virtual-repeat-container element will then not appear when values are typed in the md-autocomplete input element. What I am wondering is if there is another CSS setting on the element that forces the menu to set its width equal to the min-width? Or, if there is a CSS setting that suppresses the impact of the menu-item content to set the width of parent elements? Otherwise, I cannot determine why the width is not set to a width that is between min-width and max-width that also expands to a width that displays all of the child element contents.

mpduffey avatar Dec 11 '15 22:12 mpduffey

I used another workaround.

I didn't put the autocomplete tag inside the chips one and hid chips input field.

<md-autocomplete ...>
</md-autocomplete>
<md-chips ...>
</md-chips>



.md-chips .md-chip-input-container input:not([type]) {
    display: none
}

This should be a flexible workaround for a responsive layout.

My two cents.

albertosantini avatar Dec 15 '15 17:12 albertosantini

+1 Does anybody have a workaround? I seem to have something working, will try to submit a PR. Testing it now

Using this as a workaround:

.md-chips .md-chip-input-container {
    width: 100%;
}

.md-chips .md-chip-input-container md-autocomplete md-autocomplete-wrap {
    width: 100%;
}

This will always create a full line for autocomplete and while it may be uglier, it's fully functional. The ideal setting is a table/grid like structure where the last element uses the remaining width (if there is enough space or else make a new row). This would need a bigger rewrite which I don't have the time, personally, to do.

clshortfuse avatar Feb 11 '16 19:02 clshortfuse