react-bootstrap-typeahead icon indicating copy to clipboard operation
react-bootstrap-typeahead copied to clipboard

onSearch not being fired in AsyncTypeahead when onInputChange is present

Open zidinberu opened this issue 4 years ago • 2 comments

Title says it all. I recently upgrade a few packages, but not sure which upgrade is exactly causing the issue.

How I am using the component:

<AsyncTypeahead
  filterBy={filterBy}
  id="typeHeadAsync"
  size="lg"
  className="123"
  isLoading={isLoading}
  labelKey="word"
  minLength={1}
  searchText="በመፈለግ ላይ..."
  onSearch={ (query) => { handleSearch(query) } }
  options={wordsForPrefix}
  placeholder={asyncTypeHeadDefaultText}
  onChange={e => { onSelectHandler(e) }}
  onInputChange={ (text, event) => {onInputChangeHandler(text, event)} }
  renderMenuItemChildren={renderMenuItemChildren}
/>

If I remove / comment out onInputChange line, it works. However, with onInputChange, onSearch never gets called!

package.json:

{
  "name": "abc",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@babel/runtime": "^7.16.7",
    "@testing-library/jest-dom": "^5.16.1",
    "@testing-library/react": "^12.1.2",
    "@testing-library/user-event": "^13.5.0",
    "bootstrap": "^5.1.3",
    "cookie": "^0.4.1",
    "history": "^5.2.0",
    "js-cookie": "^3.0.1",
    "react": "^17.0.2",
    "react-audio-player": "^0.17.0",
    "react-bootstrap": "^2.1.1",
    "react-bootstrap-typeahead": "^5.2.1",
    "react-calendar": "^3.5.0",
    "react-dom": "^17.0.2",
    "react-router-dom": "^6.2.1",
    "react-select-search": "^3.0.9",
    "web-vitals": "^2.1.3"
  }
}

zidinberu avatar Jan 18 '22 00:01 zidinberu

Hi @zidinberu, thanks for reporting this issue. It's difficult to tell from your code what the problem is; can you please provide a minimal working repro?

My guess is your issue is probably being caused because the handler you're passing to onInputChange is triggering a re-render that short-circuits the onSearch function.

Possibly related to #561 and/or this SO issue.

ericgio avatar Jan 18 '22 04:01 ericgio

No response, closing. Happy to re-open if OP can provide more details.

ericgio avatar Jan 27 '22 18:01 ericgio