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

programatically trigger searches by setting value attribute #10

Merged
merged 3 commits into from
Jun 16, 2021

Conversation

mxlje
Copy link
Contributor

@mxlje mxlje commented Jun 15, 2021

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
Copy link
Contributor

nice, how/where is this userOnChange function defined?

@mxlje
Copy link
Contributor Author

mxlje commented Jun 15, 2021

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

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

const onChange = (text) => {

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

if the objects are passed to useMemo as dependencies directly the
internal equality check fails, which defeats the purpose of useMemo as
it recalculates the client on every render. That then also generates a
new search & debounced search function, which breaks the debouncing.
@mxlje mxlje merged commit a641c08 into main Jun 16, 2021
@mxlje mxlje deleted the feat/value-attribute branch June 16, 2021 10:06
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

Successfully merging this pull request may close these issues.

None yet

2 participants