geocodeearth / autocomplete-element

A custom element for use with the Geocode Earth Autocomplete API.
https://geocode.earth
MIT License
8 stars 1 forks source link

programatically trigger searches by setting `value` attribute #10

Closed mxlje closed 3 years ago

mxlje commented 3 years ago

This PR introduces the ability to set the value attribute on the custom element to trigger a search with that value. The attribute can be set using the native setAttribute API, but getters and setters are also available for an even cleaner api.

In addition to being able to set the value attribute programmatically it can also be set initially, which will trigger the search as soon as the element is initialized.

missinglink commented 3 years ago

nice, how/where is this userOnChange function defined?

mxlje commented 3 years ago

That is an optional prop that can be passed in as onChange. It is renamed to userOnChange internally to keep the external React API clean but still have a distinct name internally https://github.com/geocodeearth/autocomplete-element/blob/6bddec373cbe60b10adae53d3d429fd68711f703/src/autocomplete/autocomplete.js#L22

The custom element uses it to trigger the change event as the user types and update the value attribute of the custom element to reflect the state of the input field https://github.com/geocodeearth/autocomplete-element/blob/6bddec373cbe60b10adae53d3d429fd68711f703/src/index.js#L33

this was the case before this PR already though, that hasn’t changed.