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

change event emitted twice #13

Open
andrewharvey opened this issue Feb 23, 2017 · 2 comments
Open

change event emitted twice #13

andrewharvey opened this issue Feb 23, 2017 · 2 comments

Comments

@andrewharvey
Copy link
Collaborator

andrewharvey commented Feb 23, 2017

In the "Example with options" at http://tristen.ca/suggestions/demo/ if you select a value from the list the change event is called twice. (though it seems if you reselect the same value again it is only called once.

If I disable the dispatch of the change event at https://github.com/tristen/suggestions/blob/gh-pages/src/suggestions.js#L151 the event is only triggered once and there doesn't seem to be any side affects.

So what am I missing? Why is the event dispatched? Can we just remove it?

This affects the mapbox-gl-geocoder per mapbox/mapbox-gl-geocoder#99.

@andrewharvey
Copy link
Collaborator Author

andrewharvey commented Jul 7, 2017

The bit I'm missing is this extra code ensures the event fires on IE11. Without it IE11 won't emit the change event. 🤔

@andrewharvey
Copy link
Collaborator Author

The other think I'm missing is that this duplicate only fires when changing to something different. If you the demo you choose "Roy Hargrove", then delete and select it again, it won't duplicate.

So the scenarios are:

  1. User selects a different value from the list
    Chrome does fires a native change event + Suggestions does fire a distpatchEvent('change').
    IE11 does not fire a native change event + Suggestions does fire a distpatchEvent('change').

  2. User selects the same value from the list as already in the input
    Chrome does not fire a native change event + Suggestions does fire a distpatchEvent('change').
    IE11 does not fire a native change event + Suggestions does fire a distpatchEvent('change').

  3. User pastes a new value into the input and blur's the input, but never selected a value from the List:
    Chrome does fire a native change event + Suggestions does not fire a distpatchEvent('change').
    IE11 does fire a native change event + Suggestions does not fire a distpatchEvent('change').

  4. User pastes the same value into the input and blur's the input, but never selected a value from the List:
    Chrome does not fire a native change event + Suggestions does not fire a distpatchEvent('change').
    IE11 does not fire a native change event + Suggestions does not fire a distpatchEvent('change').

I think given the inconsistancies of the native events, it might be better to have users and gl-geocoder not listen on the native change event, but instead rely on an event Suggestion fires, and get suggestions to fire on scenario 3.

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