Skip to content

Feature request for autocomplete - more control over panel width #4196

Closed

Description

@jonbrock

Bug, feature request, or proposal:

Provide an option to control the width of the panel, perhaps via css:
<md-autocomplete #auto="mdAutocomplete" panel-class="my-autocomplete-css">

Or if it could just expand to fit the dropdown content that would be nice.

What is the expected behavior?

Allow the autocomplete dropdown panel to be a different width than the associated input field.

What is the current behavior?

The dropdown panel is the same width as the associated input field, which cuts off long values. There doesn't appear to be a way to change the width. A class or style on the md-autocomplete tag is ignored. Wrapping the options in a div with a wider style simply adds a scrollbar to the dropdown rather than widening it.

What are the steps to reproduce?

http://plnkr.co/edit/cKRWeypQ1UmpIk3s2c1E?p=preview

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

Any situation where the dropdown options contain more information than what gets displayed in the text input. In my case, I'm using the dropdown as a list of search results. Each search result contains a name, an ID, a type, and several other fields to help the user select the appropriate result. But in the text box I just show the ID.

What I'd like is to make the dropdown wide enough to show all of the information in the search results, while the text input is narrower since it only shows the ID.

Which versions of Angular, Material, OS, browsers are affected?

Latest version, Chrome, Firefox, IE, Edge

Is there anything else we should know?

Activity

  1. added
    feature
    on Apr 26, 2017
  2. shaunak1111 commented on May 11, 2017

    @shaunak1111

    A simple hack by controlling the width by using .mat-autocomplete-panel class

    .mat-autocomplete-panel {
    width : 200px;
    }

  3. willshowell commented on May 11, 2017

    @willshowell
    Contributor

    Not sure if it would work for your use-case, but another option is to have the input expand upon focus. See the repro in #4146 for an example.

  4. sadplace commented on Jun 16, 2017

    @sadplace

    I also need this.
    I need the panel width to be auto, to grow or shrink as the values inside. This way i can always see and doesn't get cut.
    So, any news about this?

  5. arlowhite commented on Jun 26, 2017

    @arlowhite

    I would set min-width rather than width. As willshowell mentioned, your other option is to expand your MdInput/MdInputContainer width when it's focused, which expands the autocomplete width.

    body .mat-autocomplete-panel {
      min-width : 200px;
    }
    
  6. ginvaell commented on Aug 24, 2017

    @ginvaell

    I also need this, as I need some panel to fit their content and some to fit input width, so the resolution above does not suit for me as it affects all autocomplete panels in project.

    I came up with a small work around, but it works with a slight delay.

    import {Directive, DoCheck, ElementRef, Input} from '@angular/core';
    import {MdAutocomplete} from '@angular/material';
    
    @Directive({
      selector: 'md-autocomplete[appAddClassToAutocomplete]',
      providers: [MdAutocomplete]
    })
    export class AddClassToAutocompleteDirective implements DoCheck {
      @Input() appAddClassToAutocomplete: string;
      private panel: ElementRef;
    
      constructor(private mdAutocomplete: MdAutocomplete) {}
    
      ngDoCheck(): void {
        const panel = this.mdAutocomplete.panel;
        if (panel && !this.panel) {
          this.panel = panel;
          panel.nativeElement.parentElement.classList.add(this.appAddClassToAutocomplete);
        }
      }
    }
  7. added 3 commits that reference this issue on Aug 24, 2017
    83a7ccf
    d0d7fda
    fc21942
  8. self-assigned this
    on Sep 19, 2017
  9. added a commit that references this issue on Sep 19, 2017
    12994d6
  10. added a commit that references this issue on Sep 29, 2017
    35f37d2
  11. added a commit that references this issue on Sep 29, 2017
    f8cd790
  12. angular-automatic-lock-bot commented on Sep 7, 2019

    @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.

  13. locked and limited conversation to collaborators on Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions