components icon indicating copy to clipboard operation
components copied to clipboard

Autocomplete selection with mouse focusing body

Open fyidev opened this issue 7 years ago • 4 comments

What is the expected behavior?

When I select an option via mouse click, it should focus the input element. This works correctly when navigating to correct option with arrow keys and pressing enter.

The issue is that if I present the autocomplete within a dropdown or dialog element that closes when a click/focus is detected outside of itself, the drop down/dialog will close everytime a mat autocomplete option is selected via mouse.

What is the current behavior?

after a mouse selection behave the same way as a keyboard/enter selection. Dont focus the body just send focus back to input.

What are the steps to reproduce?

styling is shit obviously but start typing a city in the drop down, if you key down and press enter you'll notice the drop down doesn't close. but if you use mouse to select it does close.

https://stackblitz.com/edit/create-shvowk?file=app%2Fapp.component.ts

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

material 7.3.3

Is there anything else we should know?

fyidev avatar Apr 26 '19 17:04 fyidev

The issue seems to be that bootstrap sees a click outside of its popup which is a signal to close. I don't believe there is anything we can do to circumvent their logic nor should we. You may want to file an issue with bootstrap to request a feature to prevent closing the popup when the click occurs outside of it.

andrewseguin avatar May 07 '19 21:05 andrewseguin

When using native selects, bootstrap doesn't recognize a click outside. Which lead me to believe it was on the material side.

fyidev avatar May 07 '19 22:05 fyidev

I fix it using ngZone inside the place_changed listener. Like this

autoComplete.addListener('place_changed', () => {
  this.ngZone.run(() => {
    // code
  });
});

felipeands avatar May 29 '19 16:05 felipeands

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.