material icon indicating copy to clipboard operation
material copied to clipboard

md-autocomplete no way to override width of droplist

Open elubin opened this issue 11 years ago • 14 comments

It looks like the min-width style is applied directly to the open scroll droplist as 190px, is there a way for me to override it in my CSS and have a min-width: 500px?

https://github.com/angular/material/blob/9891723e327b32d9b2f2752114c021d35ae1de05/src/components/autocomplete/js/autocompleteController.js#L75-L100

I tried md-autocomplete { min-width: 890px !important; } autocomplete-custom-template { min-width: 890px !important; }

elubin avatar Sep 22 '15 14:09 elubin

If you target the list item directly it should work fine... Assuming you've set the md-menu-class property on the md-autocomplete to "autocomplete-custom-template", then the following css should work:

.autocomplete-custom-template li { min-width: 890px; }

I don't think you would need the !important in this case, but I could be mistaken.

UncleBenjen avatar Sep 23 '15 17:09 UncleBenjen

This is kind of a poor solution as users have different screen-sizes... I have done a hack where I calculate the current width of the input element and then set the class as a inline style.. this will not solve the issue when a user resize the window but for us that is somewhat ok ;)

mackelito avatar Sep 24 '15 06:09 mackelito

+1 Would like to have more control over this. Same goes for height too.

ghost avatar Sep 24 '15 12:09 ghost

If I'm not misstaken the height is based on the elements inside so setting a height on the item li should help.. how ever it looks like the number of items visible is somewhat "fixed" to about 2.5 items.. would be nice to set that to whatever fits our needs :)

mackelito avatar Sep 24 '15 13:09 mackelito

Indeed, it's the number of items to view that I'd like to increase.

ghost avatar Sep 24 '15 13:09 ghost

@UncleBenjen thanks! FYI your width fix works on 0.10.0. broken on 0.11.0

.autocomplete-custom-template li { min-width: 890px; }

+1 for ability to show more height too

elubin avatar Sep 24 '15 15:09 elubin

You need to change selector. 0.11.0 is using the new virtual repeat directive

mackelito avatar Sep 24 '15 15:09 mackelito

@mackelito Thanks Markus. What do I need to change? View source on the new virtual repeat still seems to use ul/li and has my custom class?

elubin avatar Sep 24 '15 17:09 elubin

Just set the css to md-virtual-repeat-container element (or class)

    md-virtual-repeat-container {
      height: 300px;
    }

mackelito avatar Sep 24 '15 18:09 mackelito

While that does work, it affects ALL of my virtual repeats. (I use the md-virtual-repeater directly on my page as well)

Autocomplete appends a virtual repeat object to the bottom of the DOM with no unique id or class.

Is there a way to target just this virtual repeat? If not, could it be modified to inherit a class or attribute from autocomplete so we can target it?

elubin avatar Sep 24 '15 19:09 elubin

I guess this is unique enough since my md-virtual-repeat-container does not have the autocomplete class. I hope this works for multiple autocompletes in the same DOM.

md-virtual-repeat-container.md-autocomplete-suggestions-container {}

THANK YOU very much for your help, feedback, and guidance. Do we want to close this ticket and open a new one for the height? I did try a very quick test on height and didn't see any difference.

elubin avatar Sep 24 '15 19:09 elubin

You can close it. there are other issues regarding the height issue :)

mackelito avatar Sep 24 '15 19:09 mackelito

for temporary solution using jquery or angular we can do like below $('.md-datepicker-input').attr('readonly', 'readonly');

mandadimuralidharreddy avatar Oct 12 '16 14:10 mandadimuralidharreddy

The autocomplete results' width adjusts to the width of the md-autocomplete's containing md-input-container or equivalent; so I could adjust the autocomplete results' width by targeting .md-chip-input-container

theredpea avatar Jul 01 '17 20:07 theredpea