re-invent the react-select
Installations
npm install @blazing_hive_digital/react-select-reinvent
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Node Version
16.17.1
NPM Version
8.15.0
Contributors
Unable to fetch Contributors
Languages
TypeScript (99.3%)
JavaScript (0.69%)
CSS (0.01%)
Developer
yueleng
Download Statistics
Total Downloads
1,183
Last Day
2
Last Week
3
Last Month
10
Last Year
807
GitHub Statistics
1 Stars
60 Commits
1 Watching
11 Branches
1 Contributors
Bundle Size
92.12 kB
Minified
29.60 kB
Minified + Gzipped
Package Meta Information
Latest Version
5.7.4
Package Id
@blazing_hive_digital/react-select-reinvent@5.7.4
Unpacked Size
721.46 kB
Size
145.47 kB
File Count
136
NPM Version
8.15.0
Node Version
16.17.1
Publised On
08 Jul 2023
Total Downloads
Cumulative downloads
Total Downloads
1,183
Last day
0%
2
Compared to previous day
Last week
200%
3
Compared to previous week
Last month
25%
10
Compared to previous month
Last year
114.6%
807
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
9
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?
- v3, v4, and v5 upgrade guide
- v2 upgrade guide
- React Select v1 documentation and examples are available at v1.react-select.com
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
1import React from "react"; 2import Select from "react-select"; 3 4const options = [ 5 { value: "chocolate", label: "Chocolate" }, 6 { value: "strawberry", label: "Strawberry" }, 7 { value: "vanilla", label: "Vanilla" }, 8]; 9 10class App extends React.Component { 11 state = { 12 selectedOption: null, 13 }; 14 handleChange = (selectedOption) => { 15 this.setState({ selectedOption }, () => 16 console.log(`Option selected:`, this.state.selectedOption) 17 ); 18 }; 19 render() { 20 const { selectedOption } = this.state; 21 22 return ( 23 <Select 24 value={selectedOption} 25 onChange={this.handleChange} 26 options={options} 27 /> 28 ); 29 } 30}
With React Hooks
1import React, { useState } from "react"; 2import Select from "react-select"; 3 4const options = [ 5 { value: "chocolate", label: "Chocolate" }, 6 { value: "strawberry", label: "Strawberry" }, 7 { value: "vanilla", label: "Vanilla" }, 8]; 9 10export default function App() { 11 const [selectedOption, setSelectedOption] = useState(null); 12 13 return ( 14 <div className="App"> 15 <Select 16 defaultValue={selectedOption} 17 onChange={setSelectedOption} 18 options={options} 19 /> 20 </div> 21 ); 22}
Props
Common props you may want to specify include:
autoFocus
- focus the control when it mountsclassName
- apply a className to the controlclassNamePrefix
- apply classNames to inner elements with the given prefixisDisabled
- disable the controlisMulti
- allow the user to select multiple valuesisSearchable
- allow the user to search for matching optionsname
- generate an HTML input with this name, containing the current valueonChange
- subscribe to change eventsoptions
- specify the options the user can select fromplaceholder
- change the text displayed when no option is selectednoOptionsMessage
- ({ inputValue: string }) => string | null - Text to display when there are no optionsvalue
- 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 controlmenuIsOpen
/onMenuOpen
/onMenuClose
- control whether the menu is openinputValue
/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 controldefaultMenuIsOpen
- set the initial open value of the menudefaultInputValue
- set the initial value of the search input
Methods
React-select exposes two public methods:
focus()
- focus the control programmaticallyblur()
- blur the control programmatically
Customisation
Check the docs for more information on:
- Customising the styles
- Using custom components
- Using the built-in animated components
- Creating an async select
- Allowing users to create new options
- Advanced use-cases
- TypeScript guide
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, Emma 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 2022.
No vulnerabilities found.
No security vulnerabilities found.