Skip to content

autocomplete panel doesn't pop up when triggering focus on the input programatically #3106

Closed

Description

@fxck

see https://gist.run/?id=19eec6a0d5c69d65dbb847b12009ca9f, it starts working only after you do it the second time

@kara

Activity

  1. self-assigned this
    on Feb 15, 2017
  2. added
    P3
    on Feb 15, 2017
  3. willshowell commented on Feb 23, 2017

    @willshowell
    Contributor

    I'm not at all familiar with using ngZone, but it seems like this change fixes it

    autocomplete.ts
    
    
    /** Panel should hide itself when the option list is empty. */
    _setVisibility() {
      // Promise.resolve().then(() => this.showPanel = !!this.options.length);
      this.zone.run(() => this.showPanel = !!this.options.length);
    }
  4. bergben commented on Jun 6, 2017

    @bergben

    Is there any workaround for this for now?

  5. willshowell commented on Jun 6, 2017

    @willshowell
    Contributor

    The issue actually seems to be that clicking a button to focus the autocomplete triggers an _outsideClickStream event just after it has been opened, thus causing it to immediately close.

    As a workaround, you can use a setTimeout to focus it after the outside click event fires.

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

  6. willshowell commented on Jun 6, 2017

    @willshowell
    Contributor

    Alternatively use stopPropagation() on the click event

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

  7. willshowell commented on Jul 24, 2017

    @willshowell
    Contributor
  8. bruteforce commented on Sep 21, 2017

    @bruteforce

    Below code did the trick for me assuming focus is already on input field.

    import { MdAutocompleteTrigger} from '@angular/material';
    
    @ViewChild(MdAutocompleteTrigger) trigger;
    
    this.trigger._onChange("");
    this.trigger.openPanel();
    
  9. mpolutta commented on Apr 2, 2018

    @mpolutta

    Combined willshowell and bruteforce solutions to solve for our 508 compliance scenario. Clear button is another scenario:
    openAutoSearchPanel() {
    if (this.searchText.length === 0) {
    this.autoSearchInputTrigger._onChange('');
    this.autoSearchInputTrigger.openPanel();
    }
    }
    clearSearchText() {
    console.log('>>> clearing searchText');
    this.searchText = '';
    /// hack: Another reported workaround - Allow the ClickStream to finish executing via setTimeout.
    /// #3106
    setTimeout(() => {
    this.autoSearchInput.nativeElement.focus();
    this.openAutoSearchPanel();
    });
    }

  10. Charius commented on Apr 28, 2018

    @Charius

    yeah, got the same issue while implement custom field with autocomplete, timeout works, but this is pretty weird

  11. maxterry commented on Jul 13, 2018

    @maxterry

    Any update on this...?

  12. tombolador commented on Jul 31, 2018

    @tombolador

    +1, any updates?

  13. mischkl commented on Sep 17, 2018

    @mischkl

    This problem also affects chiplist inputs with autocomplete. 😢

  14. RajendrasinhParmar commented on Sep 22, 2018

    @RajendrasinhParmar

    Is there any workaround or fix for this issue?
    I'm having a dropdown that fetches data dynamically from the server. When I click on the chip-list field it doesn't open autocomplete list until I input any character in that.

  15. 13 remaining items

  16. added a commit that references this issue on Nov 18, 2020
    93cb86f
  17. self-assigned this
    on Nov 18, 2020
  18. Lms24 commented on Jul 2, 2021

    @Lms24

    How is this bug still open? This is a seriously annoying bug which requires an annoying workaround when used together with reactive forms.

  19. added a commit that references this issue on Aug 2, 2021
    bb163c6
  20. KissBalazs commented on Oct 27, 2021

    @KissBalazs

    This bug is still present, and makes testing with Harness quite difficult.

    This code:

        const inputField = await loader.getHarness(MatAutocompleteHarness.with(
          { selector: '#autocompleteInput' }));
        await inputField.focus();
        const options = await inputField.getOptions();
        
        expect(options.length).toBeGreaterThan(0);
    

    will fail in roughly half of the time, as the panel gets closed immediatly in those cases.

  21. crisbeto commented on Oct 27, 2021

    @crisbeto
    Member

    There's a pending PR that should make the autocomplete harness a bit more consistent in unit tests #23795.

  22. added a commit that references this issue on Jan 3, 2022
    eeb3bd0
  23. added 2 commits that reference this issue on Feb 22, 2022
    6b76469
    c0ed5ce
  24. mischkl commented on Feb 22, 2022

    @mischkl

    Glad to see it finally got fixed! 🥳 Thanks @andrewseguin

  25. angular-automatic-lock-bot commented on Mar 25, 2022

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

  26. locked and limited conversation to collaborators on Mar 25, 2022
  27. added a commit that references this issue on Apr 3, 2022
    dfc0a2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3area: material/autocomplete

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions