moroshko / react-autosuggest

WAI-ARIA compliant React autosuggest component
http://react-autosuggest.js.org
MIT License
5.97k stars 585 forks source link

Pressing Up or Down Key App crashing with undefined items #588

Open Rajdeepc opened 5 years ago

Rajdeepc commented 5 years ago

Are you reporting a bug?

@moroshko

Currently i am getting the below error:

screen shot 2018-10-24 at 1 08 08 pm screen shot 2018-10-24 at 1 08 22 pm

My code is as below:

import axios from "axios"; import * as myConstClass from "../utils/constants"; import React, { Component } from "react"; import Autosuggest from "react-autosuggest"; import getDropDownData from "../services/dropdown_service"; import Chatroom from "../components/Chatroom";

class AutoCompleteDAS extends Component { constructor(props) { super(props); this.state = { value: "", suggestions: [], placeholderTxt: "" }; this.sendValue = ""; this.showValue = ""; }

componentDidMount() { this.getDropdownList(this.props.onDropdownType); }

/**

export default AutoCompleteDAS;

iranmarcius commented 5 years ago

I'm having kind of the same problem, but when I click on items with mouse.

Zachku commented 5 years ago

Having same problem. My onChange looks like this: onChange(event, { newValue }) { this.setState({ value: newValue }); } When I'm pressing down, value of newValue is number 91 and this error occurs.

ttsirkia commented 5 years ago

I had the same problem and the reason was that my getSuggestionValue did not return a value for every possible suggestion. It used a field that did not exist for all items.

farablanco commented 5 years ago

Any solution ? I get the same problem when I try to select via the up and down keys. In addition to the trim error I also get: Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.

farablanco commented 5 years ago

Any solution ? I get the same problem when I try to select via the up and down keys. In addition to the trim error I also get: Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.

Yeah, the problem for me was in getSuggestionsValue. I was returning the default label property which my suggestion object does not support. I changed that to a supported property and it worked well afterwards.

khrome83 commented 3 years ago

I have something similar.

I have a multi-index search. When results from both indexes are present, works just fine. When results from index1 are present only, works just fine. When results from index2 are present, it breaks when hitting the down arrow, giving the error above.

The strange thing is, newValue was populated correctly. But the suggestion/hit was empty for getSuggestionValue. It just received an undefined for no reason.

If I hit up key, it works fine. If I mouse over it works fine.

If you do either of the above (up or mouse), then down starts to behave as you expect.

khrome83 commented 3 years ago

I can validate for me, that turning highlightFirstSuggestion is the cause. When this is off, it works as expected. That being said, I need the first item highlighted...

khrome83 commented 3 years ago

For me the issue was the some of the multi indexes could be empty. And highlightFirstSuggestion was set to true.

Screen Shot 2021-02-06 at 6 24 30 AM

The solution was to filter suggestions to omit anything with a empty hits array. Once I never sent a empty array of a individual index, it worked as expected.