Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. [![NPM](https://img.shields.io/npm/v/react-select.svg)](https://www.npmjs.com/package/react-select)
  2. [![CircleCI](https://circleci.com/gh/JedWatson/react-select/tree/master.svg?style=shield)](https://circleci.com/gh/JedWatson/react-select/tree/master)
  3. [![Coverage Status](https://coveralls.io/repos/JedWatson/react-select/badge.svg?branch=master&service=github)](https://coveralls.io/github/JedWatson/react-select?branch=master)
  4. [![Supported by Thinkmill](https://thinkmill.github.io/badge/heart.svg)](http://thinkmill.com.au/?utm_source=github&utm_medium=badge&utm_campaign=react-select)
  5. # React-Select
  6. The Select control for [React](https://reactjs.com). Initially built for use in [KeystoneJS](http://www.keystonejs.com).
  7. See [react-select.com](https://www.react-select.com) for live demos and comprehensive docs.
  8. See our [upgrade guide](https://github.com/JedWatson/react-select/issues/3585) for a breakdown on how to upgrade from v2 to v3.
  9. React Select is funded by [Thinkmill](https://www.thinkmill.com.au) and [Atlassian](https://atlaskit.atlassian.com). It represents a whole new approach to developing powerful React.js components that _just work_ out of the box, while being extremely customisable.
  10. Features include:
  11. - Flexible approach to data, with customisable functions
  12. - Extensible styling API with [emotion](https://emotion.sh)
  13. - Component Injection API for complete control over the UI behaviour
  14. - Controllable state props and modular architecture
  15. - Long-requested features like option groups, portal support, animation, and more
  16. If you're interested in the background, watch Jed's [talk on React Select](https://youtu.be/Eb2wy-HNGMo) at ReactNYC in March 2018.
  17. See our [upgrade guide](https://react-select.com/upgrade-guide) for a breakdown on how to upgrade from v1 to v2.
  18. The old docs and examples will continue to be available at [v1.react-select.com](https://v1.react-select.com).
  19. # Installation and usage
  20. The easiest way to use react-select is to install it from npm and build it into your app with Webpack.
  21. ```
  22. yarn add react-select
  23. ```
  24. Then use it in your app:
  25. ```js
  26. import React from 'react';
  27. import Select from 'react-select';
  28. const options = [
  29. { value: 'chocolate', label: 'Chocolate' },
  30. { value: 'strawberry', label: 'Strawberry' },
  31. { value: 'vanilla', label: 'Vanilla' },
  32. ];
  33. class App extends React.Component {
  34. state = {
  35. selectedOption: null,
  36. };
  37. handleChange = selectedOption => {
  38. this.setState({ selectedOption });
  39. console.log(`Option selected:`, selectedOption);
  40. };
  41. render() {
  42. const { selectedOption } = this.state;
  43. return (
  44. <Select
  45. value={selectedOption}
  46. onChange={this.handleChange}
  47. options={options}
  48. />
  49. );
  50. }
  51. }
  52. ```
  53. ## Props
  54. Common props you may want to specify include:
  55. - `autoFocus` - focus the control when it mounts
  56. - `className` - apply a className to the control
  57. - `classNamePrefix` - apply classNames to inner elements with the given prefix
  58. - `isDisabled` - disable the control
  59. - `isMulti` - allow the user to select multiple values
  60. - `isSearchable` - allow the user to search for matching options
  61. - `name` - generate an HTML input with this name, containing the current value
  62. - `onChange` - subscribe to change events
  63. - `options` - specify the options the user can select from
  64. - `placeholder` - change the text displayed when no option is selected
  65. - `value` - control the current value
  66. See the [props documentation](https://www.react-select.com/props) for complete documentation on the props react-select supports.
  67. ## Controllable Props
  68. You can control the following props by providing values for them. If you don't, react-select will manage them for you.
  69. - `value` / `onChange` - specify the current value of the control
  70. - `menuIsOpen` / `onMenuOpen` / `onMenuClose` - control whether the menu is open
  71. - `inputValue` / `onInputChange` - control the value of the search input (changing this will update the available options)
  72. If you don't provide these props, you can set the initial value of the state they control:
  73. - `defaultValue` - set the initial value of the control
  74. - `defaultMenuIsOpen` - set the initial open value of the menu
  75. - `defaultInputValue` - set the initial value of the search input
  76. ## Methods
  77. React-select exposes two public methods:
  78. - `focus()` - focus the control programatically
  79. - `blur()` - blur the control programatically
  80. ## Customisation
  81. Check the docs for more information on:
  82. - [Customising the styles](https://www.react-select.com/styles)
  83. - [Using custom components](https://www.react-select.com/components)
  84. - [Using the built-in animated components](https://www.react-select.com/home#animated-components)
  85. - [Creating an async select](https://www.react-select.com/async)
  86. - [Allowing users to create new options](https://www.react-select.com/creatable)
  87. - [Advanced use-cases](https://www.react-select.com/advanced)
  88. # Thanks
  89. Thank you to everyone who has contributed to this project. It's been a wild ride.
  90. If you like React Select, you should [follow me on twitter](https://twitter.com/jedwatson)
  91. Shout out to [Joss Mackison](https://github.com/jossmac), [Charles Lee](https://github.com/gwyneplaine), [Ben Conolly](https://github.com/Noviny), [Dave Brotherstone](https://github.com/bruderstein), [Brian Vaughn](https://github.com/bvaughn), and the Atlassian Design System team ❤️
  92. ## License
  93. MIT Licensed. Copyright (c) Jed Watson 2019.