We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
const languages = [ { name: 'C', year: 1972 }, { name: 'C#', year: 2000 }, { name: 'C++', year: 1983 }, { name: 'Clojure', year: 2007 }, { name: 'Elm', year: 2012 }, { name: 'Go', year: 2009 }, { name: 'Haskell', year: 1990 }, { name: 'Java', year: 1995 }, { name: 'Javascript', year: 1995 }, { name: 'Perl', year: 1987 }, { name: 'PHP', year: 1995 }, { name: 'Python', year: 1991 }, { name: 'Ruby', year: 1995 }, { name: 'Scala', year: 2003 } ]; // https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions#Using_Special_Characters function escapeRegexCharacters(str) { return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); } function getSuggestions(value) { const escapedValue = escapeRegexCharacters(value.trim()); if (escapedValue === '') { return []; } const regex = new RegExp('^' + escapedValue, 'i'); return languages.filter(language => regex.test(language.name)); } function getSuggestionValue(suggestion) { return suggestion.name; } function renderSuggestion(suggestion) { return ( <span>{suggestion.name}</span> ); } class App extends React.Component { constructor() { super(); this.state = { value: '', suggestions: [] }; } onChange = (event, { newValue, method }) => { this.setState({ value: newValue }); }; onBlur = e => { e.persist(); if (e) { console.log(e); } }; onSuggestionsFetchRequested = ({ value }) => { this.setState({ suggestions: getSuggestions(value) }); }; onSuggestionsClearRequested = () => { this.setState({ suggestions: [] }); }; render() { const { value, suggestions } = this.state; const inputProps = { placeholder: "Type 'c'", value, onChange: this.onChange, onBlur: this.onBlur }; return ( <Autosuggest suggestions={suggestions} focusInputOnSuggestionClick={false} onSuggestionsFetchRequested={this.onSuggestionsFetchRequested} onSuggestionsClearRequested={this.onSuggestionsClearRequested} getSuggestionValue={getSuggestionValue} renderSuggestion={renderSuggestion} inputProps={inputProps} /> ); } } ReactDOM.render(<App />, document.getElementById('app'));
Provide the steps to reproduce the issue, e.g.:
c
Observed behaviour: A warning pops up in the console. This warning is suppressed when you do production builds.
Expected behaviour: No Warning.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Are you reporting a bug?
https://codepen.io/moroshko/pen/LGNJMy
Provide the steps to reproduce the issue, e.g.:
c
, and wait for suggestions to appearObserved behaviour:
A warning pops up in the console. This warning is suppressed when you do production builds.
Expected behaviour:
No Warning.
The text was updated successfully, but these errors were encountered: