Closed mxlje closed 3 years ago
nice, how/where is this userOnChange
function defined?
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.
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 nativesetAttribute
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.