Registry / web-framework / react-bootstrap-typeahead

react-bootstrap-typeahead

JSON →
library6.4.1jsnpmunverified

react-bootstrap-typeahead is a React-based autocomplete component that integrates seamlessly with Bootstrap for styling, providing a familiar UI/UX. The current stable version is 6.4.1, with a major version 7.0.0-rc.x series in active development, indicating a consistent release cadence with significant updates. It offers both single and multi-selection capabilities, and is built with WAI-ARIA authoring practices compliance for accessibility. Key differentiators include its tight integration with Bootstrap 4/5, support for asynchronous data loading, customizable rendering, and a move towards composable primitives in the upcoming v7 to offer more flexibility compared to a monolithic component, making it suitable for complex auto-suggestion needs in Bootstrap-themed React applications. It dropped support for Bootstrap 4 in v7.0.0-rc.1, focusing on Bootstrap 5+.

npm install react-bootstrap-typeahead
INSTALL
IMPORT
SIG · REACT-BOOTSTRAP-TY
R
react-bootstrap-typeahead
web-frameworkjavascriptv6.4.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Typeahead
import { Typeahead } from 'react-bootstrap-typeahead';
const Typeahead = require('react-bootstrap-typeahead').Typeahead;
ESM import is preferred. CommonJS `require` is provided but less common in modern React projects and might behave differently in v7.
AsyncTypeahead
import { AsyncTypeahead } from 'react-bootstrap-typeahead';
import AsyncTypeahead from 'react-bootstrap-typeahead/AsyncTypeahead';
AsyncTypeahead is a named export from the main package entry point. Direct subpath imports might not be stable or intended.
CSS
import 'react-bootstrap-typeahead/css/Typeahead.css'; import 'react-bootstrap-typeahead/css/Typeahead.bs5.css';
<link rel="stylesheet" href="https://unpkg.com/react-bootstrap-typeahead/css/Typeahead.css" />
The CSS files are essential for proper styling. `Typeahead.bs5.css` is specifically for Bootstrap 5+ and should be included alongside the base CSS. While CDN links work, module import is typical for bundlers.
useTypeahead
import { useTypeahead } from 'react-bootstrap-typeahead';
This hook was exported in v7.0.0-rc.4 for building more flexible custom typeaheads.

This quickstart demonstrates a basic Typeahead component with static options, single selection, a clear button, and custom menu item rendering, suitable for Bootstrap 5 environments.

import React, { useState } from 'react'; import { Typeahead } from 'react-bootstrap-typeahead'; import 'react-bootstrap-typeahead/css/Typeahead.css'; import 'react-bootstrap-typeahead/css/Typeahead.bs5.css'; // For Bootstrap 5 interface Option { id: number; label: string; } const options: Option[] = [ { id: 1, label: 'Apple' }, { id: 2, label: 'Banana' }, { id: 3, label: 'Orange' }, { id: 4, label: 'Pineapple' }, { id: 5, label: 'Strawberry' }, ]; function MyTypeaheadComponent() { const [selected, setSelected] = useState<Option[]>([]); return ( <div className="container mt-5"> <h3>Basic Typeahead Example</h3> <Typeahead id="my-typeahead" options={options} labelKey="label" placeholder="Choose a fruit..." onChange={(selectedOptions) => { setSelected(selectedOptions as Option[]); console.log('Selected:', selectedOptions); }} selected={selected} clearButton highlightOnlyResult renderMenuItemChildren={(option, props) => ( <div key={option.id}> <span>{option.label}</span> </div> )} /> {selected.length > 0 && ( <div className="mt-3"> Selected items: {selected.map(item => item.label).join(', ')} </div> )} </div> ); } export default MyTypeaheadComponent;
Debug
Known issues
breakingVersion 7.0.0 introduces several breaking changes. `onInputChange` no longer receives the input value as the first argument, and falsy menu items are filtered out from `Menu`. Custom rendering of menu items via `MenuItem` requires explicitly passing `onItemSelect`.
fix
Consult the official upgrade guide (`https://github.com/ericgio/react-bootstrap-typeahead/blob/7.x/docs/Upgrading.md`) for specific migration steps. Adjust `onInputChange` callback signatures and ensure `onItemSelect` is passed to custom `MenuItem` components.
affects: >=7.0.0-rc.1
breakingSupport for Bootstrap 4 has been dropped in v7.0.0-rc.1. Projects using Bootstrap 4 will need to remain on a v6.x release or upgrade their Bootstrap version.
fix
If migrating to v7, upgrade your project's Bootstrap dependency to v5+. If remaining on Bootstrap 4, use `react-bootstrap-typeahead` v6.x.
affects: >=7.0.0-rc.1
gotchaIt is critical to include the necessary CSS files for `react-bootstrap-typeahead` to render correctly. The base `Typeahead.css` is always needed, and `Typeahead.bs5.css` is specifically for Bootstrap 5 projects.
fix
Ensure `import 'react-bootstrap-typeahead/css/Typeahead.css';` and, if using Bootstrap 5, `import 'react-bootstrap-typeahead/css/Typeahead.bs5.css';` are present in your application's entry point or component where the Typeahead is used.
affects: >=1.0.0
breakingIn v7.0.0-rc.1, the component moved away from HOCs and monolithic design towards composable hooks and components, removing previous internal managers and core typeahead components. The `gap` CSS property is now used for multi-select input styling.
fix
Review the v7 upgrade guide (`https://github.com/ericgio/react-bootstrap-typeahead/blob/7.x/docs/Upgrading.md#v70-breaking-changes`) for detailed changes regarding component structure and styling. Adopt new hooks like `useTypeahead` for custom implementations.
affects: >=7.0.0-rc.1
gotchaDocumentation and live examples on the official site (`http://ericgio.github.io/react-bootstrap-typeahead/`) primarily apply to the most recent release. Using an outdated version might lead to discrepancies between documentation and actual component behavior.
fix
Always refer to the version-specific documentation if not using the latest release, or upgrade to the latest stable version to align with current examples and features.
affects: <current_latest
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'Typeahead')
Attempting to import `Typeahead` using a CommonJS `require` statement in an environment where the module is configured for ESM, or using incorrect destructuring.
fix
Use the ESM import syntax: `import { Typeahead } from 'react-bootstrap-typeahead';`
Typeahead component renders without styling or with misaligned elements.
The necessary CSS files for the component were not imported or linked correctly in the project.
fix
Ensure that `import 'react-bootstrap-typeahead/css/Typeahead.css';` is present. If using Bootstrap 5, also include `import 'react-bootstrap-typeahead/css/Typeahead.bs5.css';`.
My custom menu item component does not correctly select items or close the menu.
When providing a custom `renderMenuItemChildren` or `MenuItem` component in v7, the `onItemSelect` prop (or equivalent function from `useTypeahead`) was not explicitly passed down to enable selection behavior.
fix
Refer to the v7 upgrade guide or examples for custom menu rendering. Ensure `onItemSelect` is properly passed to your custom `MenuItem` to handle selection events.
Upgrade
Version history
6.4.1latest on npm
Audit
Dependencies
reactrequiredPeer dependency for React component rendering.
react-domrequiredPeer dependency for DOM manipulation in React.
Agent activity
4 hits · last 30 days
node
4
Resources
react-bootstrap-typeahead — npm install react-bootstrap-typeahead · libregistry