Skip to content

Request : md-option autoHeight support for <md-select> and/or <md-autocomplete> #4071

Closed

Description

@gedclack

Bug, feature request, or proposal:

Feature Request

What is the expected behavior?

option to choose between fixed height or auto-height to fit md-option's contents.

What is the current behavior?

md-option's height is fixed to 48px

What is the use-case or motivation for changing an existing behavior?

its very helpful and descriptive to have an additional text (maybe in smaller font-size) to show more information in the options, rather than having one line of text which only show one information.

Currently on :

Angular material 2.0.0-beta.3

Activity

  1. changed the title [-]Request : Auto-Grow md-option support for <md-select> and <md-autocomplete>[/-] [+]Request : md-option NewLine support for <md-select> and <md-autocomplete>[/+] on Apr 13, 2017
  2. changed the title [-]Request : md-option NewLine support for <md-select> and <md-autocomplete>[/-] [+]Request : md-option autoHeight support for <md-select> and/or <md-autocomplete>[/+] on Apr 13, 2017
  3. willshowell commented on Apr 13, 2017

    @willshowell
    Contributor

    Possible duplicate of #3883

  4. added
    feature
    on Apr 13, 2017
  5. jelbourn commented on Apr 13, 2017

    @jelbourn
    Contributor

    Potentially doable for autocomplete, would be much more difficult for select.

  6. added
    P5
    on Apr 13, 2017
  7. gedclack commented on Apr 15, 2017

    @gedclack
    Author

    @jelbourn yes it will be great to have it for autocomplete, I believe many Web Apps will rely heavily on autocomplete to select and filter hundreds of options (and I don't think md-select is the right component for that -- since it has no textbox to type and find options)

  8. fxck commented on Apr 16, 2017

    @fxck
    Contributor

    @gedclack you are only saying that under the assumption that md-select can not do that, which it certainly can and there is pending (for two months) PR for it already #3211

    In fact, I think autocomplete is definitely NOT the right component for selecting, that's what select is for, as autocomplete doesn't by default (and currently not even with option) enforce the selection to be the one of the list, it simply does the completion.

    Also @jelbourn it will only be more difficult if you do that the actual "autoheight", if you allow the user to set the default (fixed) height, instead of hardcoding it, or do something like md-line on md-list, it shouldn't be difficult at all.

    and

    Based on the material design spec, we don't see multi-line options for being permitted

    I don't see it being prohibited either, but if it is the case, allowing the user to set the fixed height of all items should still be considered.

  9. gedclack commented on Apr 17, 2017

    @gedclack
    Author

    @fxck well it will be great then 👍 , I am just assuming with the current version of Material2.

    @jelbourn IMHO (and with current version of Material2), if you add this #3334 that will be the solution for #3211

  10. PeS82 commented on May 24, 2017

    @PeS82

    I believe having the possibility to use ng-template instead of md-option in options list for md-autocomplete would be nice. Please?

  11. gedclack commented on Jul 20, 2017

    @gedclack
    Author

    @jelbourn is this resolved in the recent updates?
    *haven't touch angular projects for a few weeks now..

  12. ksmirnoff commented on Oct 8, 2017

    @ksmirnoff

    @jelbourn is there an ETA for providing multiline support for autocomplete suggestion panel?

  13. amitport commented on Oct 23, 2017

    @amitport
    Contributor

    I'm using this workaround and it works fine for now:

    mat-list.<<my-list-class>> ::ng-deep  .mat-list-item-content {
      height: <<new height>>;
    }
    
  14. fxck commented on Oct 23, 2017

    @fxck
    Contributor

    That's not gonna work. The height is internally hardwired so they can calculate position of the active item upon opening. Overriding the height just in css is going to mess it up.

  15. amitport commented on Oct 23, 2017

    @amitport
    Contributor

    @fxck it worked well enough for my use case. That being said, it's definitely not a solution and this issue should be open.

    In any case, a have another workaround that should play nicer with other css rules:

    <mat-list-item *ngFor="<<let something of somethings>>">
      <div style="height: <<my-height>>; width: 100%;">
        <span matLine></span><span matLine></span><span matLine></span><span matLine></span>
        <<my-line-content>>
      </div>
    </mat-list-item>
    

    (material applies 'mat-multi-line' class when there are more than 3 matLine) (IMHO we probably need something like MatFitContent directive on mat-list-item that does the same)

  16. fxck commented on Oct 23, 2017

    @fxck
    Contributor

    Also apparently you are talking about mat-list, while this issue is about mat-autocomplete and mat-select.

  17. amitport commented on Oct 23, 2017

    @amitport
    Contributor

    @fxck ohh... you're right, sorry, I thought I was writing in #4114 (which should be re-opened IMO)

  18. faelmorais commented on Feb 9, 2018

    @faelmorais

    Any updates on this function?

  19. charlie-elverson commented on Jun 27, 2018

    @charlie-elverson

    This takes care of my needs for displaying multiple lines of content in a single mat-option.

    <mat-option *ngFor="let emp of empDataSource | async" style="height: 90px;" [value]="emp"> {{emp.searchDisplay}} <br> Building: {{emp.thing1}} <br> Room: {{emp.thing2}} </mat-option>

  20. leogoesger commented on Nov 5, 2018

    @leogoesger

    Could someone provide an update on this? What would the proper syntax for using mat-option if
    displayed value is too long?

  21. martin-dmtrv commented on Dec 20, 2019

    @martin-dmtrv

    Adding this style to mat-option appears to solve the problem for us:
    style="min-height: 48px; line-height: normal; height: auto; padding: 10px 20px;"

    So final component should like something like:

    <mat-form-field class="w-100">
        <input matInput placeholder="Role" aria-label="Role" [matAutocomplete]="auto" [formControl]="roleCtrl">
        <mat-autocomplete #auto="matAutocomplete">
            <mat-option *ngFor="let Role of Roles | async" [value]="Role.name" style="min-height: 48px; line-height: normal; height: auto; padding: 10px 20px;">
                <span>{{Role.name}}</span><br />
                <small class="text-grey">{{Role.description}}</small>
            </mat-option>
        </mat-autocomplete>
    </mat-form-field>
    
  22. striky1 commented on Mar 20, 2020

    @striky1

    I'm using @martin-dmtrv solution but with these styles:

    min-height: 48px; line-height: 1.15; height: auto; padding: 8px 16px; white-space: normal;

    Which more following base Material styles.

  23. Jadamae77 commented on Jun 3, 2020

    @Jadamae77

    Any updates?

  24. gedclack commented on Jun 15, 2020

    @gedclack
    Author

    for now I'm using similar workaround, adding this css below and using it on my AutoComplete's <mat-option>

    .multiline-auto-complete-options {
    	height: auto !important;
    	line-height: normal !important;
    	padding: 8px 16px !important;
    }
    
  25. crisbeto commented on Apr 23, 2021

    @crisbeto
    Member

    This is supported in the MDC-based version of mat-autocomplete and mat-select from @angular/material-experimental. I'll close this issue, because porting the feature back to the non-MDC version won't be practical.

  26. angular-automatic-lock-bot commented on May 24, 2021

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  27. locked and limited conversation to collaborators on May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P5area: material/selectfeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions