Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete touch devices issue #884

Closed
betocantu93 opened this issue Jan 21, 2018 · 4 comments
Closed

Autocomplete touch devices issue #884

betocantu93 opened this issue Jan 21, 2018 · 4 comments

Comments

@betocantu93
Copy link
Contributor

Found a curious bug, while on touch devices (tested on Chrome devtools), if you click outside of the autocomplete after selecting an item from a dynamic list generated by a server query, the onSelectionChange method is executed again with a null item. This doesn't happen at all while on mouse devices, which makes this hard to debug. I also think this might be related to #767 and #787

@betocantu93
Copy link
Contributor Author

betocantu93 commented Jan 21, 2018

From Ember Basic Dropdown guides I found this

http://ember-basic-dropdown.com/docs/dropdown-events

image

And noticed that the method select from Power-select.js is being triggered when tapping outside of the trigger component, like something similar to onBlur, and the event passed is undefined so no clue what would be changing or triggering this programatically

select(selected, e) {
      console.log('selecting', e);
      let publicAPI = this.get('publicAPI');
      if (!isEqual(publicAPI.selected, selected)) {
        this.get('onchange')(selected, publicAPI, e);
      }
    },

And it happens before the onBlur

@betocantu93
Copy link
Contributor Author

Tracked it down to onInput, seems it gets triggered with the event "change".

@betocantu93
Copy link
Contributor Author

betocantu93 commented Jan 21, 2018

Found the root, handleInputLocal method in paper-autocomplete-trigger, sends the action select with null if there is something already selected, it turns that on touch devices, handleInputLocal gets triggered by tapping outside of the trigger, which leads to the bug because it replaces the selected item with null.

My solution so far is to check for the type of the event, like this:

/components/paper-autocomplete-trigger.js

  handleInputLocal(e) {
      // If something is already selected when the user types, it should clear selection
      if (this.get('selected') && e.type === "input") {
        this.get('select').actions.select(null);
      }
      this.get('onInput')(e.target ? e : { target: { value: e } });
      this.set('text', e.target ? e.target.value : e);
    }

Because the other way it gets called with event type "change", so checking for input ensures that the user is typing...

OR

Getting rid of onchange action binding in paper-autocomplete-trigger.hbs, because oninput and onchange trigger the handleInputLocal, but at least in all my use cases in touch devices, onchange setting null is not desired.

@betocantu93
Copy link
Contributor Author

I guess this is solved by #956 . Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant