
Security News
Node.js Homepage Adds Paid Support Link, Prompting Contributor Pushback
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
react-bootstrap-typeahead
Advanced tools
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.
It is highly recommended that you use npm to install the module in your project and build using a tool like webpack or browserify.
npm install react-bootstrap-typeahead
If you want to use the component in a standalone manner, both an unminified development version and a minified production version are included in the build
folder.
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.
An example file is included with the module. Simply open index.html
in a browser. 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} . |
options required | array | Full set of options, including any pre-selected options. | |
placeholder | string | Placeholder text for the input. | |
selected | array | [] | The selected option(s) displayed in the input. Use this prop if you want to control the component via its parent. |
Token
and MenuItem
renderingFAQs
React typeahead with Bootstrap styling
The npm package react-bootstrap-typeahead receives a total of 166,653 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
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.
Research
Security News
The Socket Research Team investigates a malicious Python typosquat of a popular password library that forces Windows shutdowns when input is incorrect.