|
| 1 | +# rc-select |
| 2 | +--- |
| 3 | + |
| 4 | +React Select |
| 5 | + |
| 6 | +[![NPM version][npm-image]][npm-url] |
| 7 | +[![build status][travis-image]][travis-url] |
| 8 | +[![Test coverage][coveralls-image]][coveralls-url] |
| 9 | +[](https://david-dm.org/react-component/select) |
| 10 | +[](https://david-dm.org/react-component/select?type=dev) |
| 11 | +[![npm download][download-image]][download-url] |
| 12 | +[](https://github.com/react-component/select) |
| 13 | + |
| 14 | +[Storybook]: https://github.com/storybooks/press/blob/master/badges/storybook.svg |
| 15 | +[npm-image]: http://img.shields.io/npm/v/rc-select.svg?style=flat-square |
| 16 | +[npm-url]: http://npmjs.org/package/rc-select |
| 17 | +[travis-image]: https://img.shields.io/travis/react-component/select.svg?style=flat-square |
| 18 | +[travis-url]: https://travis-ci.org/react-component/select |
| 19 | +[coveralls-image]: https://img.shields.io/coveralls/react-component/select.svg?style=flat-square |
| 20 | +[coveralls-url]: https://coveralls.io/r/react-component/select?branch=maste |
| 21 | +[node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square |
| 22 | +[node-url]: http://nodejs.org/download/ |
| 23 | +[download-image]: https://img.shields.io/npm/dm/rc-select.svg?style=flat-square |
| 24 | +[download-url]: https://npmjs.org/package/rc-select |
| 25 | + |
| 26 | +## Screenshots |
| 27 | + |
| 28 | +<img src="https://user-images.githubusercontent.com/8186664/50768510-a8b30680-12bb-11e9-8251-0e0ed82c5076.png" /> |
| 29 | + |
| 30 | +## Feature |
| 31 | + |
| 32 | +* support ie9,ie9+,chrome,firefox,safari |
| 33 | + |
| 34 | +### Keyboard |
| 35 | + |
| 36 | +* Open select (focus input || focus and click) |
| 37 | +* KeyDown/KeyUp/Enter to navigate menu |
| 38 | + |
| 39 | +## install |
| 40 | + |
| 41 | +[](https://npmjs.org/package/rc-select) |
| 42 | + |
| 43 | +## Usage |
| 44 | + |
| 45 | +### basic use |
| 46 | + |
| 47 | +```js |
| 48 | +import Select, {Option, OptGroup} from 'rc-select'; |
| 49 | + |
| 50 | +var c = ( |
| 51 | + <Select> |
| 52 | + <Option value="jack">jack</Option> |
| 53 | + <Option value="lucy">lucy</Option> |
| 54 | + <Option value="yiminghe">yiminghe</Option> |
| 55 | + </Select> |
| 56 | +); |
| 57 | +React.render(c, container); |
| 58 | +``` |
| 59 | + |
| 60 | +## API |
| 61 | + |
| 62 | +### Select props |
| 63 | + |
| 64 | +| name | description | type | default | |
| 65 | +|----------|----------------|----------|--------------| |
| 66 | +|id | html id to set on the component wrapper | String | '' | |
| 67 | +|className | additional css class of root dom node | String | '' | |
| 68 | +|data-\* | html data attributes to set on the component wrapper | String | '' | |
| 69 | +|prefixCls | prefix class | String | '' | |
| 70 | +|animation | dropdown animation name. only support slide-up now | String | '' | |
| 71 | +|transitionName | dropdown css animation name | String | '' | |
| 72 | +|choiceTransitionName | css animation name for selected items at multiple mode | String | '' | |
| 73 | +|dropdownMatchSelectWidth | whether dropdown's with is same with select | bool | true | |
| 74 | +|dropdownClassName | additional className applied to dropdown | String | - | |
| 75 | +|dropdownStyle | additional style applied to dropdown | Object | {} | |
| 76 | +|dropdownAlign | additional align applied to dropdown | Object | {} | |
| 77 | +|dropdownMenuStyle | additional style applied to dropdown menu | Object | {} | |
| 78 | +|notFoundContent | specify content to show when no result matches. | String | 'Not Found' | |
| 79 | +|tokenSeparators | separator used to tokenize on tag/multiple mode | string[]? | | |
| 80 | +|open | control select open | bool | | |
| 81 | +|defaultOpen | control select default open | bool | | |
| 82 | +|placeholder | select placeholder | React Node | | |
| 83 | +|showSearch | whether show search input in single mode | bool | true | |
| 84 | +|showArrow | whether show arrow | bool | true (single mode), false (multiple mode) | |
| 85 | +|allowClear | whether allowClear | bool | false | |
| 86 | +|tags | when tagging is enabled the user can select from pre-existing options or create a new tag by picking the first choice, which is what the user has typed into the search box so far. | bool | false | |
| 87 | +|maxTagTextLength | max tag text length to show | number | - | |
| 88 | +|maxTagCount | max tag count to show | number | - | |
| 89 | +|maxTagPlaceholder | placeholder for omitted values | ReactNode/function(omittedValues) | - | |
| 90 | +|combobox | enable combobox mode(can not set multiple at the same time) | bool | false | |
| 91 | +|multiple | whether multiple select | bool | false | |
| 92 | +|disabled | whether disabled select | bool | false | |
| 93 | +|filterOption | whether filter options by input value. default filter by option's optionFilterProp prop's value | bool | true/Function(inputValue:string, option:Option) | |
| 94 | +|optionFilterProp | which prop value of option will be used for filter if filterOption is true | String | 'value' | |
| 95 | +|optionLabelProp | render option value or option children as content of select | String: 'value'/'children' | 'value' | |
| 96 | +|defaultValue | initial selected option(s) | String/Array<String> | - | |
| 97 | +|value | current selected option(s) | String/Array<String>/{key:String, label:React.Node}/Array<{key, label}> | - | |
| 98 | +|firstActiveValue | first active value when there is no value | String/Array<String> | - | |
| 99 | +|labelInValue| whether to embed label in value, see above value type | Bool | false | |
| 100 | +|backfill| whether backfill select option to search input (Only works in single and combobox mode) | Bool | false | |
| 101 | +|onChange | called when select an option or input value change(combobox) | function(value, option:Option/Array<Option>) | - | |
| 102 | +|onSearch | called when input changed | function | - | |
| 103 | +|onBlur | called when blur | function | - | |
| 104 | +|onFocus | called when focus | function | - | |
| 105 | +|onPopupScroll | called when menu is scrolled | function | - | |
| 106 | +|onSelect | called when a option is selected. param is option's value and option instance | Function(value, option:Option) | - | |
| 107 | +|onDeselect | called when a option is deselected. param is option's value. only called for multiple or tags | Function(value, option:Option) | - | |
| 108 | +|onInputKeyDown | called when key down on input | Function(event) | - | |
| 109 | +|defaultActiveFirstOption | whether active first option by default | bool | true | |
| 110 | +|getPopupContainer | container which popup select menu rendered into | function(trigger:Node):Node | function(){return document.body;} | |
| 111 | +|getInputElement| customize input element | function(): Element | - | |
| 112 | +|showAction| actions trigger the dropdown to show | String[]? | - | |
| 113 | +|autoFocus| focus select after mount | Bool | - | |
| 114 | +| autoClearSearchValue | auto clear search input value when multiple select is selected/deselected | boolean | true | |
| 115 | +| inputIcon | specify the select arrow icon | ReactNode | - | |
| 116 | +| clearIcon | specify the clear icon | ReactNode | - | |
| 117 | +| removeIcon | specify the remove icon | ReactNode | - | |
| 118 | +| menuItemSelectedIcon | specify the remove icon | ReactNode \| (props: MenuItemProps) => ReactNode | - | |
| 119 | +| dropdownRender | render custom dropdown menu | (menu: React.Node, props: MenuProps) => ReactNode | - | |
| 120 | +| loading | show loading icon in arrow | Boolean | false | |
| 121 | + |
| 122 | +### Methods |
| 123 | + |
| 124 | +| name | description | parameters | return | |
| 125 | +|----------|----------------|----------|--------------| |
| 126 | +|focus | focus select programmably | - | - | |
| 127 | +|blur | blur select programmably | - | - | |
| 128 | + |
| 129 | +### Option props |
| 130 | + |
| 131 | +| name | description | type | default | |
| 132 | +|----------|----------------|----------|--------------| |
| 133 | +|className | additional class to option | String | '' | |
| 134 | +|disabled | no effect for click or keydown for this item | bool | false | |
| 135 | +|key | if react want you to set key, then key is same as value, you can omit value | String/number | - | |
| 136 | +|value | default filter by this attribute. if react want you to set key, then key is same as value, you can omit value | String/number | - | |
| 137 | +|title | if you are not satisfied with auto-generated `title` which is show while hovering on selected value, you can customize it with this property | String | - | |
| 138 | + |
| 139 | + |
| 140 | +### OptGroup props |
| 141 | + |
| 142 | +| name | description | type | default | |
| 143 | +|----------|----------------|----------|--------------| |
| 144 | +|label | group label | String/React.Element | - | |
| 145 | +|key | - | String | - | |
| 146 | +|value | default filter by this attribute. if react want you to set key, then key is same as value, you can omit value | String | - | |
| 147 | + |
| 148 | + |
| 149 | +## Development |
| 150 | + |
| 151 | +``` |
| 152 | +npm install |
| 153 | +npm start |
| 154 | +``` |
| 155 | + |
| 156 | +## Example |
| 157 | + |
| 158 | +http://localhost:9001/ |
| 159 | + |
| 160 | +online example: http://react-component.github.io/select/ |
| 161 | + |
| 162 | +## Test Case |
| 163 | + |
| 164 | +``` |
| 165 | +npm test |
| 166 | +``` |
| 167 | + |
| 168 | +## Coverage |
| 169 | + |
| 170 | +``` |
| 171 | +npm run coverage |
| 172 | +``` |
| 173 | + |
| 174 | + |
| 175 | +## License |
| 176 | + |
| 177 | +rc-select is released under the MIT license. |
0 commit comments