Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

marcelltoth/react-select-reborn

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Archived!

Archived since react-select started getting updates again.

NPM CircleCI Coverage Status

React-Select-Reborn

Reborn?

This is a fork of the original react-select repository, with the aim to bring it back to life by pulling in the abandoned Pull Requests and fixing the outstanding issues of react-select.

Why the fork

Unfortunately react-select seemes to be abandoned by its maintainers. Perfectly good pull requests are not reviewed or merged, which is a sad situation given the numerious users of the library. This is documented in detail here: JedWatson#3910 The aim of this project is to bring react-select back to life, fix the outstanding issues (at the time of writing this there are 1278 open issues on react-select) and keep improving this outstanding tool many rely on day to day.

Upgrading from react-select v3?

This project aims to maintain semver compatibility with react-select v3. What this means is if you were using react-select v3, you should not expect breaking changes until react-select-reborn hits v4.

The component

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

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-reborn

Then use it in your app:

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

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

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:

Upgrading from an older version

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 Jed Watson, the original creator of react-select, Joss Mackison, Charles Lee, Ben Conolly, Dave Brotherstone, Brian Vaughn, and the Atlassian Design System team ❤️

License

MIT Licensed. Copyright (c) Jed Watson 2019.

About

The Select Component for React.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%