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

searchFn callback fires twice when typing in search bar #101

Closed
MustafaFaris opened this issue Jun 3, 2020 · 5 comments · Fixed by #131
Closed

searchFn callback fires twice when typing in search bar #101

MustafaFaris opened this issue Jun 3, 2020 · 5 comments · Fixed by #131
Labels
bug Something isn't working

Comments

@MustafaFaris
Copy link

Hi there, I'm having a problem with the searchFn callback, apparently each time you type in the search bar the searchFn callback gets fired twice. The same thing doesn't seem to happen with handleKeyDownFn callback, however the state it returns is a bit late so I can't use it.

I've created this sandbox here to demonstrate the issue, try typing in the search bar and then check the console.

@sanusart sanusart added the bug Something isn't working label Jun 3, 2020
@AnDyro751
Copy link

Any solution?

@akuji1993
Copy link
Contributor

akuji1993 commented Jul 21, 2020

If you're looking for an easy solution to wrap this for now, you could either debounce, or just do this:

const onSearch = e => { if (searchValue !== e.state.search) { setSearchValue(e.state.search); } };

That way you have pretty much the same solution that a componentDidUpdate with an equality check would give you.

Edited Sandbox here: https://codesandbox.io/s/searchfn-callback-issue-glbzx?file=/src/App.js

@sanusart
Copy link
Owner

I am extremely out of time recently, so if someone can submit a patch for this it could be great. If not it would have to wait a bit. Apologies if inconvenient.

@stale
Copy link

stale bot commented Sep 19, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Stale issue with no response or lack of info label Sep 19, 2020
@sanusart sanusart removed the stale Stale issue with no response or lack of info label Sep 19, 2020
sanusart pushed a commit that referenced this issue Oct 20, 2020
…ing in the search bar (#131)

* Working searchFn example.

* Remove debug code.

* Undo indentation

* Restore changes.

* Remove debug code.

* Restore return.

* Add test for a custom function.

* Add test coverage for custom search function.

* Apply code review suggestions.
sanusart added a commit that referenced this issue Oct 29, 2020
…when typing in the search bar (#131)"

This reverts commit 12164f9.
sanusart added a commit that referenced this issue Oct 29, 2020
…when typing in the search bar (#131)" (#135)

This reverts commit 12164f9.
@sanusart sanusart reopened this Oct 29, 2020
@sanusart
Copy link
Owner

reverted for now

sanusart pushed a commit that referenced this issue Nov 17, 2020
…ing in the search bar, #134, #133 (#136)

* Working searchFn example.

* Remove debug code.

* Undo indentation

* Restore changes.

* Remove debug code.

* Restore return.

* Add test for a custom function.

* Add test coverage for custom search function.

* Apply code review suggestions.

* Reset searchResults on blur.

* Clear search results on dropdown; update search results on options change.
sanusart added a commit that referenced this issue Nov 29, 2020
* master: (27 commits)
  v4.7.0 See changelog: https://github.com/sanusart/react-dropdown-select/blob/master/CHANGELOG.md
  FIX (searchFn)[#101] searchFn callback should only call once when typing in the search bar, #134, #133 (#136)
  4.6.1
  Revert "FIX (searchFn)[#101] searchFn callback should only call once when typing in the search bar (#131)" (#135)
  v4.6.0 See changelog: https://github.com/sanusart/react-dropdown-select/blob/master/CHANGELOG.md
  FIX (searchFn)[#101] searchFn callback should only call once when typing in the search bar (#131)
  v4.5.2 See changelog: https://github.com/sanusart/react-dropdown-select/blob/master/CHANGELOG.md
  FIX (style): Accepts a short color (#127)
  v4.5.1 See changelog: https://github.com/sanusart/react-dropdown-select/blob/master/CHANGELOG.md
  FIX (duplicates)[#116]: more proper way to check dupes, closes #116
  FIX (duplicates): PR comments
  FIX (duplicates)[#116]: more proper way to check dupes, closes #116
  bump version
  v4.5.0 See changelog: https://github.com/sanusart/react-dropdown-select/blob/master/CHANGELOG.md
  FIX (input) [#114]: fix chars truncated, closes #114
  v4.4.2 See changelog: https://github.com/sanusart/react-dropdown-select/blob/master/CHANGELOG.md
  FIX (box-model): add box-sizing border-box, closes #94 (#104)
  Bump websocket-extensions from 0.1.3 to 0.1.4 (#102)
  DOCS (example): add import to example, thanks to @karland, closes #93
  CHORE (types): fix keepOpen type | closes #95 (#96)
  ...

# Conflicts:
#	__tests__/__snapshots__/index.spec.js.snap
#	__tests__/components/__snapshots__/DropdownHandle.spec.js.snap
#	package-lock.json
#	src/components/DropdownHandle.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants