Skip to content

Commit

Permalink
#55: added real file with the real name
Browse files Browse the repository at this point in the history
  • Loading branch information
st3phan-cs committed Feb 27, 2020
1 parent 80be3c2 commit 485dbf5
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/components/pages/SearchResult/Autocomplete.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React, { Component } from 'react';
import { Highlight, connectAutoComplete } from 'react-instantsearch-dom';
import AutoSuggest from 'react-autosuggest';

class Autocomplete extends Component {
// @ts-ignore
state = { value: this.props.currentRefinement };

onChange = (event: any, { newValue }: any) => {
this.setState({ value: newValue });
};

onSuggestionsFetchRequested = ({ value }: any) => {
// @ts-ignore
this.props.refine(value);
};

onSuggestionsClearRequested = () => {
// @ts-ignore
this.props.refine();
};

getSuggestionValue(hit: any) {
return hit.name;
}

renderSuggestion(hit: any) {
return <Highlight attribute="name" hit={hit} tagName="mark" />;
}

render() {
const { hits }: any = this.props;
const { value } = this.state;

const inputProps = {
placeholder: 'Search for a product...',
onChange: this.onChange,
value,
};

return (
<AutoSuggest
suggestions={hits}
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
onSuggestionsClearRequested={this.onSuggestionsClearRequested}
getSuggestionValue={this.getSuggestionValue}
renderSuggestion={this.renderSuggestion}
inputProps={inputProps}
/>
);
}
}

// @ts-ignore
export default connectAutoComplete(Autocomplete);

0 comments on commit 485dbf5

Please sign in to comment.