rs

react-select

The Select Component for React.js

Showing:

Popularity

Downloads/wk

3.2M

GitHub Stars

23.6K

Maintenance

Last Commit

9d ago

Contributors

499

Package

Dependencies

7

License

MIT

Type Definitions

Built-In

Tree-Shakeable

Yes?

Reviews

Average Rating

4.3/567
Read All Reviews
Charles8211
jsgiant
soydavidpaucar
preveenraj
ajayesivan
s-r-aman
abhijithvijayan

Top Feedback

15Great Documentation
12Easy to Use
10Performant
8Highly Customizable
3Hard to Use
2Bleeding Edge

Readme

NPM CircleCI Coverage Status Supported by Thinkmill

React-Select

The Select control for React. Initially built for use in KeystoneJS.

See react-select.com for live demos and comprehensive docs.

React Select is funded by Thinkmill and Atlassian. It represents a whole new approach to developing powerful React.js components that just work out of the box, while being extremely customisable.

For the story behind this component, watch Jed's talk at React Conf 2019 - building React Select

Features include:

  • Flexible approach to data, with customisable functions
  • Extensible styling API with emotion
  • Component Injection API for complete control over the UI behaviour
  • Controllable state props and modular architecture
  • Long-requested features like option groups, portal support, animation, and more

Using an older version?

Installation and usage

The easiest way to use react-select is to install it from npm and build it into your app with Webpack.

yarn add react-select

Then use it in your app:

With React Component

import React from 'react';
import Select from 'react-select';

const options = [
  { value: 'chocolate', label: 'Chocolate' },
  { value: 'strawberry', label: 'Strawberry' },
  { value: 'vanilla', label: 'Vanilla' },
];

class App extends React.Component {
  state = {
    selectedOption: null,
  };
  handleChange = (selectedOption) => {
    this.setState({ selectedOption }, () =>
      console.log(`Option selected:`, this.state.selectedOption)
    );
  };
  render() {
    const { selectedOption } = this.state;

    return (
      <Select
        value={selectedOption}
        onChange={this.handleChange}
        options={options}
      />
    );
  }
}

With React Hooks

import React, { useState } from 'react';
import Select from 'react-select';

const options = [
  { value: 'chocolate', label: 'Chocolate' },
  { value: 'strawberry', label: 'Strawberry' },
  { value: 'vanilla', label: 'Vanilla' },
];

export default function App() {
  const [selectedOption, setSelectedOption] = useState(null);

  return (
    <div className="App">
      <Select
        defaultValue={selectedOption}
        onChange={setSelectedOption}
        options={options}
      />
    </div>
  );
}

Props

Common props you may want to specify include:

  • autoFocus - focus the control when it mounts
  • className - apply a className to the control
  • classNamePrefix - apply classNames to inner elements with the given prefix
  • isDisabled - disable the control
  • isMulti - allow the user to select multiple values
  • isSearchable - allow the user to search for matching options
  • name - generate an HTML input with this name, containing the current value
  • onChange - subscribe to change events
  • options - specify the options the user can select from
  • placeholder - change the text displayed when no option is selected
  • noOptionsMessage - ({ inputValue: string }) => string | null - Text to display when there are no options
  • value - control the current value

See the props documentation for complete documentation on the props react-select supports.

Controllable Props

You can control the following props by providing values for them. If you don't, react-select will manage them for you.

  • value / onChange - specify the current value of the control
  • menuIsOpen / onMenuOpen / onMenuClose - control whether the menu is open
  • inputValue / onInputChange - control the value of the search input (changing this will update the available options)

If you don't provide these props, you can set the initial value of the state they control:

  • defaultValue - set the initial value of the control
  • defaultMenuIsOpen - set the initial open value of the menu
  • defaultInputValue - set the initial value of the search input

Methods

React-select exposes two public methods:

  • focus() - focus the control programatically
  • blur() - blur the control programatically

Customisation

Check the docs for more information on:

Typescript

The v5 release represents a rewrite from JavaScript to Typescript. The types for v4 and earlier releases are available at @types. See the TypeScript guide for how to use the types starting with v5.

Thanks

Thank you to everyone who has contributed to this project. It's been a wild ride.

If you like React Select, you should follow me on twitter!

Shout out to Joss Mackison, Charles Lee, Ben Conolly, Tom Walker, Nathan Bierema, Eric Bonow, Mitchell Hamilton, Dave Brotherstone, Brian Vaughn, and the Atlassian Design System team who along with many other contributors have made this possible ❤️

License

MIT Licensed. Copyright (c) Jed Watson 2021.

Rate & Review

Great Documentation15
Easy to Use12
Performant10
Highly Customizable8
Bleeding Edge2
Responsive Maintainers0
Poor Documentation2
Hard to Use3
Slow0
Buggy2
Abandoned0
Unwelcoming Community0
100
Charles821153 Ratings47 Reviews
1 month ago
Great Documentation
Easy to Use
Highly Customizable

It is the select component to react which at first built for keystone.js. It helps me to control over the UI behaviour by component API injection. By using styles prop I can style individual components with custom CSS. The async version is debouncable and provides auto-suggestions. It helps me to create new options using the creatable component.


3
abhijithvijayan
katharinbenson
ashikmeerankutty
Anil ChowdaryHyderabad78 Ratings78 Reviews
Frontend dev | React | Typescript | Javascript | Tailwind CSS
September 23, 2020
Easy to Use

I used react-select in my projects. Easy to use but I have found difficult to customise the styles for the drop-down. Documentation is not good enough to know more about customisation of the items and value container which is providing by react-select.


2
Denisdubovikov96
hood
David PaucarQuito, Ecuador26 Ratings40 Reviews
I'm David, a full-time full-stack freelance developer 👨‍💻 working since 2017 🚀
2 months ago
Great Documentation
Highly Customizable

Complete and useful select library that I've used on my learning path for React.Js, so customizable with common option to add it on each project, from begginer to more experimented developers, low learning curve so I implemented in short time to put all data that I need and make it works as quickly as possible


1
riginoommen
Preveen RajKochi, Kerala, India58 Ratings49 Reviews
Software Engineer @bigbinary
4 months ago
Great Documentation
Easy to Use
Performant
Highly Customizable

It's the best package I have found that would meet every requirements for a select component. It's support for multi-select, structured and grouped dropdown view and search clear functionality are the most I used. Asynchronous options are also a plus point.


1
ajayesivan
Ajay SivanIndia32 Ratings44 Reviews
Engineering Manager @bigbinary
4 months ago

When I wanted to implement a complex dropdown component I used this package. Initially, I had trouble figuring out the proper ways to implement this, but after a while of browsing through the docs, it became easier and easier.


1
vishnuprasad-95