MCPcopy Index your code
hub / github.com/moroshko/react-autosuggest

github.com/moroshko/react-autosuggest @v10.1.0 sqlite

repository ↗ · DeepWiki ↗ · release v10.1.0 ↗
270 symbols 651 edges 78 files 0 documented · 0% 2 cross-repo links
README

Build Status Contributors Coverage Status

npm Downloads npm Version gzip size

React Autosuggest

Project Status

Looking for maintainers!

Unfortunately, I don't have the time to maintain this project anymore. If you are interested to help, please reach out to me on Twitter @moroshko.

Demo

Check out the Homepage and the Codepen examples.

Features

Installation

yarn add react-autosuggest

or

npm install react-autosuggest --save

You can also use the standalone UMD build:

<script src="https://unpkg.com/react-autosuggest/dist/standalone/autosuggest.js"></script>

Basic Usage

import React from 'react';
import Autosuggest from 'react-autosuggest';

// Imagine you have a list of languages that you'd like to autosuggest.
const languages = [
  {
    name: 'C',
    year: 1972
  },
  {
    name: 'Elm',
    year: 2012
  },
  ...
];

// Teach Autosuggest how to calculate suggestions for any given input value.
const getSuggestions = value => {
  const inputValue = value.trim().toLowerCase();
  const inputLength = inputValue.length;

  return inputLength === 0 ? [] : languages.filter(lang =>
    lang.name.toLowerCase().slice(0, inputLength) === inputValue
  );
};

// When suggestion is clicked, Autosuggest needs to populate the input
// based on the clicked suggestion. Teach Autosuggest how to calculate the
// input value for every given suggestion.
const getSuggestionValue = suggestion => suggestion.name;

// Use your imagination to render suggestions.
const renderSuggestion = suggestion => (



    {suggestion.name}



);

class Example extends React.Component {
  constructor() {
    super();

    // Autosuggest is a controlled component.
    // This means that you need to provide an input value
    // and an onChange handler that updates this value (see below).
    // Suggestions also need to be provided to the Autosuggest,
    // and they are initially empty because the Autosuggest is closed.
    this.state = {
      value: '',
      suggestions: []
    };
  }

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

  // Autosuggest will call this function every time you need to update suggestions.
  // You already implemented this logic above, so just use it.
  onSuggestionsFetchRequested = ({ value }) => {
    this.setState({
      suggestions: getSuggestions(value)
    });
  };

  // Autosuggest will call this function every time you need to clear suggestions.
  onSuggestionsClearRequested = () => {
    this.setState({
      suggestions: []
    });
  };

  render() {
    const { value, suggestions } = this.state;

    // Autosuggest will pass through all these props to the input.
    const inputProps = {
      placeholder: 'Type a programming language',
      value,
      onChange: this.onChange
    };

    // Finally, render it!
    return (
      <Autosuggest
        suggestions={suggestions}
        onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
        onSuggestionsClearRequested={this.onSuggestionsClearRequested}
        getSuggestionValue={getSuggestionValue}
        renderSuggestion={renderSuggestion}
        inputProps={inputProps}
      />
    );
  }
}

Props

Prop Type Required Description
suggestions Array These are the suggestions that will be displayed. Items can take an arbitrary shape.
onSuggestionsFetchRequested Function Will be called every time you need to recalculate suggestions.
onSuggestionsClearRequested Function * Will be called every time you need to set suggestions to [].
getSuggestionValue Function Implement it to teach Autosuggest what should be the input value when suggestion is clicked.
renderSuggestion Function Use your imagination to define how suggestions are rendered.
inputProps Object Pass through arbitrary props to the input. It must contain at least value and onChange.
containerProps Object Pass through arbitrary props to the container. Useful if you need to override the default props set by Autowhatever, for example, for accessibility.
onSuggestionSelected Function Will be called every time suggestion is selected via mouse or keyboard.
onSuggestionHighlighted Function Will be called every time the highlighted suggestion changes.
shouldRenderSuggestions Function When the input is focused, Autosuggest will consult this function when to render suggestions. Use it, for example, if you want to display suggestions when input value is at least 2 characters long.
alwaysRenderSuggestions Boolean Set it to true if you'd like to render suggestions even when the input is not focused.
highlightFirstSuggestion Boolean Set it to true if you'd like Autosuggest to automatically highlight the first suggestion.
focusInputOnSuggestionClick Boolean Set it to false if you don't want Autosuggest to keep the input focused when suggestions are clicked/tapped.
multiSection Boolean Set it to true if you'd like to display suggestions in multiple sections (with optional titles).
renderSectionTitle Function

when multiSection={true} | Use your imagination to define how section titles are rendered. | | getSectionSuggestions | Function | ✓

when multiSection={true} | Implement it to teach Autosuggest where to find the suggestions for every section. | | renderInputComponent | Function | | Use it only if you need to customize the rendering of the input. | | renderSuggestionsContainer | Function | | Use it if you want to customize things inside the suggestions container beyond rendering the suggestions themselves. | | theme | Object | | Use your imagination to style the Autosuggest. | | id | String | | Use it only if you have multiple Autosuggest components on a page. |

suggestions (required)

Array of suggestions to display. The only requirement is that suggestions is an array. Items in this array can take an arbitrary shape.

For a plain list of suggestions, every item in suggestions represents a single suggestion. It's up to you what shape every suggestion takes. For example:

const suggestions = [
  {
    text: "Apple"
  },
  {
    text: "Banana"
  },
  {
    text: "Cherry"
  },
  {
    text: "Grapefruit"
  },
  {
    text: "Lemon"
  }
];

For multiple sections, every item in suggestions represents a single section. Again, it's up to you what shape every section takes. For example:

```js const suggestions = [ { title: "A", suggestions: [ { id: "100", text: "Apple" }, { id: "101", text: "Apricot" } ] }, { title: "B", suggestions: [ { id: "102", text: "Banana" } ] }, { title: "C", suggestions: [ {

Core symbols most depended-on inside this repo

focusAndSetInputValue
called by 84
test/helpers.js
clickDown
called by 61
test/autowhatever/autowhatever-helpers.js
expectSuggestions
called by 38
test/helpers.js
expectHighlightedSuggestion
called by 37
test/helpers.js
clickEscape
called by 26
test/helpers.js
clickEnter
called by 25
test/autowhatever/autowhatever-helpers.js
focusInput
called by 22
test/helpers.js
clickSuggestion
called by 20
test/helpers.js

Shape

Function 159
Method 59
Class 52

Languages

TypeScript100%

Modules by API surface

test/helpers.js47 symbols
src/Autosuggest.js21 symbols
test/autowhatever/autowhatever-helpers.js18 symbols
src/Autowhatever.js13 symbols
test/textarea/AutosuggestApp.js11 symbols
test/render-input-component/AutosuggestApp.js11 symbols
test/render-suggestions-container/AutosuggestApp.js10 symbols
test/keep-suggestions-on-select/AutosuggestApp.js10 symbols
test/focus-first-suggestion-clear-on-enter/AutosuggestApp.js9 symbols
demo/standalone/app.js8 symbols
test/multi-section/AutosuggestApp.js7 symbols
demo/src/components/App/components/Examples/components/MultipleSections/MultipleSections.js7 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

@babel/cli7.8.4 · 1×
@babel/core7.9.0 · 1×
@babel/plugin-proposal-class-properties7.8.3 · 1×
@babel/preset-env7.9.0 · 1×
@babel/preset-react7.9.4 · 1×
@babel/register7.9.0 · 1×
@istanbuljs/nyc-config-babel3.0.0 · 1×
autoprefixer9.7.5 · 1×
autosuggest-highlight3.1.1 · 1×
babel-eslint10.1.0 · 1×
babel-loader8.1.0 · 1×
babel-plugin-istanbul6.0.0 · 1×

For agents

$ claude mcp add react-autosuggest \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact