Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-virtualized-select

bvaughn132.2kMIT3.1.3TypeScript support: definitely-typed

Drop-down menu for React with windowing to support large numbers of options.

readme

React Virtualized Select

NPM version NPM license NPM total downloads NPM monthly downloads PayPal donate button Patreon donate button

Demos available here: http://bvaughn.github.io/react-virtualized-select/

react-virtualized-select example

Getting started

Install react-virtualized-select using npm.

npm install react-virtualized-select --save

ES6, CommonJS, and UMD builds are available with each distribution. For example:

// Make sure to import default styles.
// This only needs to be done once; probably during bootstrapping process.
import 'react-select/dist/react-select.css'
import 'react-virtualized/styles.css'
import 'react-virtualized-select/styles.css'

// Then import the virtualized Select HOC
import VirtualizedSelect from 'react-virtualized-select'

Alternately you can load a global-friendly UMD build:

<link rel="stylesheet" href="path-to-react-select/dist/react-select.css">
<link rel="stylesheet" href="path-to-react-virtualized/styles.css">
<link rel="stylesheet" href="path-to-react-virtualized-select/styles.css">

<script src="path-to-react-virtualized-select/dist/umd/react-virtualized-select.js"></script>

Simple Example

react-select-virtualized works just like react-select. You pass it an array of options, along with any other parameters supported by the Select component. Here's a simple example:

import React, { Component } from 'react'
import VirtualizedSelect from 'react-virtualized-select'

import 'react-select/dist/react-select.css'
import 'react-virtualized/styles.css'
import 'react-virtualized-select/styles.css'

class MySelect extends Component {
  constructor (props) {
    super(props)

    this.state = {}
  }

  render () {
    const options = [
      { label: "One", value: 1 },
      { label: "Two", value: 2 },
      { label: "Three", value: 3, disabled: true }
      // And so on...
    ]

    return (
      <VirtualizedSelect
        options={options}
        onChange={(selectValue) => this.setState({ selectValue })}
        value={this.state.selectValue}
      />
    )
  }
}

React Virtualized Select Props

The additional parameters introduced by react-select-virtualized are optional. They are:

Property Type Description
async PropTypes.bool Use Select.Async internally; if this property is specified then a loadOptions method should also be used.
maxHeight PropTypes.number Max height of options menu; defaults to 200 pixels.
optionHeight PropTypes.number or PropTypes.func Option height (defaults to 35 pixels). Dynamic height can be supported via a function with the signature ({ option: Object }): number
optionRenderer PropTypes.func Custom option renderer; (see below for signature).
selectComponent PropTypes.func Use a specific select HOC (eg Select, Select.Creatable, Select.Async or Select.AsyncCreatable); defaults to Select (or Select.Async if async flag is true).

Custom Option Renderer

You can override the built-in option renderer by specifying your own optionRenderer property. Your renderer should return a React element that represents the specified option. It will be passed the following named parameters:

Property Type Description
focusedOption Object The option currently-focused in the dropdown. Use this property to determine if your rendered option should be highlighted or styled differently.
focusedOptionIndex number Index of the currently-focused option.
focusOption Function Callback to update the focused option; for example, you may want to call this function on mouse-over.
key string A unique identifier for each element created by the renderer.
labelKey string Attribute of option that contains the display text.
option Object The option to be rendered.
options Array<Object> Array of options (objects) contained in the select menu.
selectValue Function Callback to update the selected values; for example, you may want to call this function on click.
style Object Styles that must be passed to the rendered option. These styles are specifying the position of each option (required for correct option displaying in the dropdown).
valueArray Array<Object> Array of the currently-selected options. Use this property to determine if your rendered option should be highlighted or styled differently.
valueKey string Attribute of option that contains the value.

changelog

Changelog

3.1.3
  • Added cursor: pointer style by defalut to select options.
3.1.2
  • (Nothing.)
3.1.1
  • Added missing valueKey to custom option renderer params.
3.1.0
  • Default option renderer supports a className property on options.
3.0.1
3.0.0
  • Same as v2.4.2 but with an updated external dependency versions (eg react-virtualized 8.x to 9.x, new prop-types lib, react alpha 16, etc).
2.4.2
  • Backwards compat bugfix for require('...').default usecase (see issue #57).
2.4.1
  • 🎉 UMD build fixed to properly set window.VirtualizedSelect (@armed - #56)
2.4.0
2.3.0
  • 🎉 focus method added to VirtualizedSelect (@Syynth - #41)
2.2.0
  • 🎉 Default option renderer highlights selected option in bold (@the-spyke - #40)
2.1.1

Added a workaround for a bug in Creatable (react-select 1.0.0-rc2). Clicking on the placeholder item now successfully creates new options. See issue #33.

2.1.0

Added listProps prop to enable pass-through of additional, custom properties to the underlying react-virtualized List.

2.0.2

Dramatically reduced library size by limiting the parts of react-virtualized that are imported.

2.0.1

Utilizes babel-plugin-transform-runtime to remove babelHelpers from the built dist. This enables support without requiring the babel-external-helpers plugin in application code.

2.0.0

Updates to react-virtualized 8.x release. Read more about version 8 changes here.

Contains no new user-facing functionality but requires a major update due to the updated optionRenderer interface. Renderers will now receive 2 additional named properties: key and style. Both should be passed through to the top-level element of their rendered response. For example:

// react-virtualized-select 1.x
function optionRendererBefore ({ option, ...rest }) {
  return (
    <div>
      {option.name}
    </div>
  )
}

// react-virtualized-select 2.x
function optionRendererAfter ({ key, option, style, ...rest }) {
  return (
    <div
      key={key}
      style={style}
    >
      {option.name}
    </div>
  )
}
1.4.0

Added selectComponent option to enable users to choose a sepecific select HOC (eg Select.Creatable).

1.3.0

Added support for disabled attribute in options array.

1.2.0

Added support for async options (Select.Async) via new async boolean property.

1.1.1

Fixed a regression for non-function optionHeight values.

1.1.0

Supports dynamic option heights via optionHeight as a function. Function should implement the following signature: ({ option: Object }): number

1.0.0

First major release; interface now stable.

0.0.4

Dependency bump for React 15.0 now that it has been released.

0.0.3

Finalized props signature of VirtualizedSelect; changed rowRenderer to optionRenderer to better align with react-select terminology.

0.0.2

Moved react-select and react-virtualized from peerDependencies to dependencies block. Updated CommonJS/ES module build to export VirtualizedSelect as a default.

0.0.1

Initial release.

0.0.0

Reserved NPM package name.