New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mesosphere-react-typeahead

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mesosphere-react-typeahead

React-based typeahead component

  • 0.5.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by57.14%
Maintainers
1
Weekly downloads
 
Created
Source

React Bootstrap Typeahead

React-based typeahead component that uses Bootstrap as a base for styles and behaviors and supports both single- and multi-selection. Try a live example.

build status npm version npm downloads

Please note that this library is under active development and the APIs may change.

Installation

Use NPM to install the module in your project and build using a tool like webpack or browserify.

npm install react-bootstrap-typeahead

To generate UMD modules, both minified and unminified, download the project and run npm run build.

Usage

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}
/>

Single & Multi-Selection

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}
/>

Controlled vs. Uncontrolled

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}
/>

Data

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.

Rendering

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 */
  }}
/>

CSS

The component tries to use as little CSS as possible, relying primarily on Bootstrap or any Bootstrap themes for styling. Some minimal styling is included in Typeahead.css and Token.css and should ideally be included wherever you're using the component.

Example

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.

Documentation

Props

NameTypeDefaultDescription
alignstring'justify'Specify menu alignment. The default value is justify, which makes the menu as wide as the input and truncates long values. Specifying left or right will align the menu to that side and the width will be determined by the length of menu item values.
allowNewbooleanfalseAllows 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.
defaultSelectedarray[]Specify any pre-selected options. Use only if you want the component to be uncontrolled.
disabledbooleanWhether to disable the input. Will also disable selections when multiple={true}.
emptyLabelstring'No matches found.'Message to display in the menu if there are no valid results.
labelKeystring'label'Specify which option key to use for display. By default, the selector will use the label key.
maxHeightnumber300Maximum height of the dropdown menu, in px.
multiplebooleanfalseWhether or not multiple selections are allowed.
newSelectionPrefixstring'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}.
onBlurfunctionCallback fired when the input is blurred. Receives an event.
onChangefunctionCallback fired whenever items are added or removed. Receives an array of the selected options.
onInputChangefunctionCallback fired when user-input text changes. Receives the text string.
options requiredarrayFull set of options, including any pre-selected options.
placeholderstringPlaceholder text for the input.
renderMenuItemChildrenfunctionProvides a hook for customized rendering of menu item contents.
selectedarray[]The selected option(s) displayed in the input. Use this prop if you want to control the component via its parent.

Keywords

FAQs

Package last updated on 20 Jul 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc