Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

react-autosuggest

> 前端框架
Open source

WAI-ARIA compliant React autosuggest component

5.9K stars0 likes1 views
WebsiteGitHub

About

WAI-ARIA compliant React autosuggest component

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.

React-Autosuggest AI Bot

React-Autosuggest Bot will help you understand this repository better. You can ask for code examples, installation guide, debugging help and much more.

Demo

Check out the Homepage and the Codepen examples.

Features

  • WAI-ARIA compliant, with support for ARIA attributes and keyboard interactions
  • Mobile friendly
  • Plugs in nicely to Flux and Redux applications
  • Full control over suggestions rendering
  • Suggestions can be presented as plain list or multiple sections
  • Suggestions can be retrieved asynchronously
  • Highlight the first suggestion in the list if you wish
  • Supports styling using CSS Modules, Radium, Aphrodite, JSS, and more
  • You decide when to show suggestions (e.g. when user types 2 or more characters)
  • Always render suggestions (useful for mobile and modals)
  • Pass through arbitrary props to the input (e.g. placeholder, type, onChange, onBlur, or any other), or take full control on the rendering of the input (useful for integration with other libraries)
  • Thoroughly tested

Installation

bash
yarn add react-autosuggest

or

bash
npm install react-autosuggest --save

You can also use the standalone UMD build:

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

Basic Usage

…

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:

javascript
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:

javascript
const suggestions = [
  {
    title: "A",
    suggestions: [
      {
        id: "100",
        text: "Apple"
      },
      {
        id: "101",
        text: "Apricot"
      }
    ]
  },
  {
    title: "B",
    suggestions: [
      {
        id: "102",
        text: "Banana"
      }
    ]
  },
  {
    title: "C",
    suggestions: [
      {
        id: "103",
        text: "Cherry"
      }
    ]
  }
];

onSuggestionsFetchRequested (required)

This function will be called every time you might need to update suggestions. It has the following signature:

javascript
function onSuggestionsFetchRequested({ value, reason })

where:

  • value - the current value of the input
  • reason - string describing why onSuggestionsFetchRequested was called. The possible values are:
    • 'input-changed' - user typed something
    • 'input-focused' - input was focused
    • 'escape-pressed' - user pressed Escape to clear the input (and suggestions are shown for empty input)
    • 'suggestions-revealed' - user pressed Up or Down to reveal suggestions
    • 'suggestion-selected' - user selected a suggestion when alwaysRenderSuggestions={true}

onSuggestionsClearRequested (required unless alwaysRenderSuggestions={true})

This function will be called every time you need to clear suggestions.

All you have to do in this function is to set suggestions to [].

<a name="on-suggestions-clear-requested-

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptaccessibleautocompleteautosuggestreact

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架