
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
react-bootstrap-typeahead
Advanced tools
The react-bootstrap-typeahead package is a flexible, robust, and highly customizable typeahead (autocomplete) component for React. It is built using Bootstrap styles and provides a variety of features to enhance user experience in form inputs.
Basic Typeahead
This feature allows you to create a basic typeahead input where users can type and get suggestions from a predefined list of options.
import React from 'react';
import { Typeahead } from 'react-bootstrap-typeahead';
const options = ['John', 'Paul', 'George', 'Ringo'];
function BasicTypeahead() {
return (
<Typeahead
id="basic-typeahead"
labelKey="name"
options={options}
placeholder="Choose a name..."
/>
);
}
export default BasicTypeahead;
Multiple Selections
This feature allows users to select multiple options from the typeahead suggestions, making it useful for forms that require multiple inputs.
import React from 'react';
import { Typeahead } from 'react-bootstrap-typeahead';
const options = ['John', 'Paul', 'George', 'Ringo'];
function MultiSelectTypeahead() {
return (
<Typeahead
id="multi-select-typeahead"
labelKey="name"
multiple
options={options}
placeholder="Choose several names..."
/>
);
}
export default MultiSelectTypeahead;
Custom Rendering
This feature allows you to customize the rendering of the typeahead options, providing more control over the appearance and behavior of the suggestions.
import React from 'react';
import { Typeahead } from 'react-bootstrap-typeahead';
const options = [
{ id: 1, name: 'John' },
{ id: 2, name: 'Paul' },
{ id: 3, name: 'George' },
{ id: 4, name: 'Ringo' }
];
function CustomRenderTypeahead() {
return (
<Typeahead
id="custom-render-typeahead"
labelKey="name"
options={options}
placeholder="Choose a Beatle..."
renderMenuItemChildren={(option, props) => (
<div>
<span>{option.name}</span>
</div>
)}
/>
);
}
export default CustomRenderTypeahead;
react-autosuggest is a popular package for building autocomplete and autosuggest components in React. It offers a high degree of customization and flexibility, similar to react-bootstrap-typeahead, but does not rely on Bootstrap for styling.
downshift is a highly customizable library for building autocomplete, dropdown, and select components in React. It provides a set of primitives to build complex components, offering more flexibility but requiring more setup compared to react-bootstrap-typeahead.
react-select is a flexible and beautiful Select Input control for React with support for multi-select, async options, and more. It is highly customizable and provides a rich set of features, making it a strong alternative to react-bootstrap-typeahead.
React-based typeahead component that uses standard the Bootstrap theme for as a base and supports both single- and multi-selection. Try a live example.
Please note that this library is under active development and the APIs may change.
Use NPM to install the module in your project and build using a tool like webpack or browserify.
npm install react-bootstrap-typeahead
Make sure you have the appropriate CSS loaders (see notes below).
To generate UMD modules, both minified and unminified, download the project and run npm run build
.
react-bootstrap-typeahead
works very much like any standard input
element. It requires an array of options to display, similar to a select
.
var Typeahead = require('react-bootstrap-typeahead');
<Typeahead
onChange={this._handleChange}
options={myData}
/>
react-bootstrap-typeahead
allows single-selection by default, but also supports multi-selection. Simply set the multiple
prop and the component turns into a tokenizer:
<Typeahead
multiple
onChange={this._handleChange}
options={myData}
/>
Like an input
, the component can be controlled or uncontrolled. Use the selected
prop to control it via the parent, or defaultSelected
to optionally set defaults and then allow the component to control itself.
<Typeahead
onChange={this._handleChange}
options={myData}
selected={selected}
/>
react-bootstrap-typeahead
has some expectations about the shape of your data. It expects an array of objects, each of which should have a string property to be used as the label for display. By default, the key is named label
, but you can specify a different key via the labelKey
prop.
var myData = [
{id: 1, name: 'John'},
{id: 2, name: 'Miles'},
{id: 3, name: 'Charles'},
{id: 4, name: 'Herbie'},
];
<Typeahead
labelKey="name"
onChange={this._handleChange}
options={myData}
/>
As far as the source of the data, the component simply handles rendering and selection. It is agnostic about the data source (eg: an async endpoint), which should be handled separately.
react-bootstrap-typeahead
is intended to work with standard Bootstrap components and styles. It provides basic rendering for your data by default, but also allows for more advanced options should the need arise.
renderMenuItemChildren
Allows you to control the contents of a menu item. Your function will be passed the TypeaheadMenu
props, an individual option from your data list, and the index:
<Typeahead
options={options}
renderMenuItemChildren={(props, option, idx) => {
/* Render custom contents here */
}}
/>
The component tries to use as little CSS as possible, relying primarily on Bootstrap or any Bootstrap themes for styling. There is a small amount, which is bundled with the JS files.
Browserify users will need to use browserify-css (or something similar) to handle the CSS bundling, while Webpack user will need to use css-loader and/or style-loader in their webpack config file.
An example file is included with the NPM module. Simply open example/index.html
in a browser. If you're using the repository code, you'll need to run npm run example
to build the example index file. You can then open the HTML file as described above. You can also try the live example.
Name | Type | Default | Description |
---|---|---|---|
allowNew | boolean | false | Allows the creation of new selections on the fly. Note that any new items will be added to the list of selections, but not the list of original options unless handled as such by Typeahead 's parent. |
defaultSelected | array | [] | Specify any pre-selected options. Use only if you want the component to be uncontrolled. |
disabled | boolean | Whether to disable the input. Will also disable selections when multiple={true} . | |
emptyLabel | string | 'No matches found.' | Message to display in the menu if there are no valid results. |
labelKey | string | 'label' | Specify which option key to use for display. By default, the selector will use the label key. |
maxHeight | number | 300 | Maximum height of the dropdown menu, in px. |
multiple | boolean | false | Whether or not multiple selections are allowed. |
newSelectionPrefix | string | 'New selection:' | Provides the ability to specify a prefix before the user-entered text to indicate that the selection will be new. No-op unless allowNew={true} . |
onChange | function | Callback for handling selected values. | |
onInputChange | function | Callback for handling changes to the user-input text. | |
options required | array | Full set of options, including any pre-selected options. | |
placeholder | string | Placeholder text for the input. | |
renderMenuItemChildren | function | Provides a hook for customized rendering of menu item contents. | |
selected | array | [] | The selected option(s) displayed in the input. Use this prop if you want to control the component via its parent. |
FAQs
React typeahead with Bootstrap styling
The npm package react-bootstrap-typeahead receives a total of 163,423 weekly downloads. As such, react-bootstrap-typeahead popularity was classified as popular.
We found that react-bootstrap-typeahead demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.