material icon indicating copy to clipboard operation
material copied to clipboard

md-autocomplete escape behavior is inconsistent with modern browsers (Chrome)

Open clshortfuse opened this issue 11 years ago • 3 comments

When using Chrome's built in autocomplete/autofill feature on forms, escape will close the autocomplete box and the cursor will stay focused on the last character used. Pressing escape again will pass the event back up to event. For example, if I'm using an md-input field in md-dialog, it would close the dialog (as expected).

With md-autocomplete, escape will close the autocomplete box and for some odd reason clear the entire field and then lose focus. Also, pressing escape won't propagate the event up. This means you can't close a dialog from an md-autocomplete input field ever.

I have fixed this in my personal fork, but I believe it should be discussed a bit before I supply a pull request.

I'm assuming the idea was to copy the Chrome address bar behavior, but that's not how autocomplete should work on actual pages.

clshortfuse avatar Oct 15 '15 20:10 clshortfuse

The changes would be from this:

case $mdConstant.KEY_CODE.ESCAPE:
    event.stopPropagation();
    event.preventDefault();
    clearValue();

    // Force the component to blur if they hit escape
    doBlur(true);

to this:

case $mdConstant.KEY_CODE.ESCAPE:
    if (ctrl.hidden && !ctrl.loading) //fixes escape event not being sent up
        return;
    event.stopPropagation();
    event.preventDefault();

    // Clear and remove results
    ctrl.matches = [];
    ctrl.hidden  = true;
    ctrl.index   = getDefaultIndex();

Again, if you guys want to have a different style user interaction from Chrome's Autofill, that's totally fine, just we should have the option to allow events to pass up, remove the forced blur, and close the dialog on escape.

clshortfuse avatar Oct 15 '15 20:10 clshortfuse

+1

by not passing up the event, it also incorrectly blocks bottomsheet from closing

elubin avatar Oct 22 '15 20:10 elubin

@ThomasBurleson Hey Thomas, was this bug fixed? If so, in what release will the fix be? Thanks!

TrancaDev avatar Jun 02 '16 23:06 TrancaDev