UNPKG

8.88 kBMarkdownView Raw
1# rc-select
2
3---
4
5React Select
6
7[![NPM version][npm-image]][npm-url]
8[![npm download][download-image]][download-url]
9[![build status][github-actions-image]][github-actions-url]
10[![Test coverage][coveralls-image]][coveralls-url]
11[![Dependencies][david-image]](david-url)
12[![DevDependencies][david-dev-image]][david-dev-url]
13[![bundle size][bundlephobia-image]][bundlephobia-url]
14
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/master?style=flat-square
18[travis-url]: https://travis-ci.com/react-component/select
19[github-actions-image]: https://github.com/react-component/select/workflows/CI/badge.svg
20[github-actions-url]: https://github.com/react-component/select/actions
21[coveralls-image]: https://img.shields.io/coveralls/react-component/select.svg?style=flat-square
22[coveralls-url]: https://coveralls.io/r/react-component/select?branch=master
23[codecov-image]: https://img.shields.io/codecov/c/github/react-component/select/master.svg?style=flat-square
24[codecov-url]: https://codecov.io/gh/react-component/select/branch/master
25[david-url]: https://david-dm.org/react-component/select
26[david-image]: https://david-dm.org/react-component/select/status.svg?style=flat-square
27[david-dev-url]: https://david-dm.org/react-component/select?type=dev
28[david-dev-image]: https://david-dm.org/react-component/select/dev-status.svg?style=flat-square
29[download-image]: https://img.shields.io/npm/dm/rc-select.svg?style=flat-square
30[download-url]: https://npmjs.org/package/rc-select
31[bundlephobia-url]: https://bundlephobia.com/result?p=rc-select
32[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-select
33
34## Screenshots
35
36<img src="https://gw.alipayobjects.com/zos/antfincdn/d13eUZlgdJ/tupian.png" />
37
38## Feature
39
40- support IE11+,Chrome,Firefox,Safari
41
42### Keyboard
43
44- Open select (focus input || focus and click)
45- KeyDown/KeyUp/Enter to navigate menu
46
47## install
48
49[![rc-select](https://nodei.co/npm/rc-select.png)](https://npmjs.org/package/rc-select)
50
51## Usage
52
53### basic use
54
55```js
56import Select, { Option } from 'rc-select';
57
58export default () => (
59 <Select>
60 <Option value="jack">jack</Option>
61 <Option value="lucy">lucy</Option>
62 <Option value="yiminghe">yiminghe</Option>
63 </Select>
64);
65```
66
67## API
68
69### Select props
70
71| name | description | type | default |
72| --- | --- | --- | --- |
73| id | html id to set on the component wrapper | String | '' |
74| className | additional css class of root dom node | String | '' |
75| data-\* | html data attributes to set on the component wrapper | String | '' |
76| prefixCls | prefix class | String | '' |
77| animation | dropdown animation name. only support slide-up now | String | '' |
78| transitionName | dropdown css animation name | String | '' |
79| choiceTransitionName | css animation name for selected items at multiple mode | String | '' |
80| dropdownMatchSelectWidth | whether dropdown's with is same with select | bool | true |
81| dropdownClassName | additional className applied to dropdown | String | - |
82| dropdownStyle | additional style applied to dropdown | Object | {} |
83| dropdownAlign | additional align applied to dropdown | Object | {} |
84| dropdownMenuStyle | additional style applied to dropdown menu | Object | {} |
85| notFoundContent | specify content to show when no result matches. | String | 'Not Found' |
86| tokenSeparators | separator used to tokenize on tag/multiple mode | string[]? | |
87| open | control select open | bool | |
88| defaultOpen | control select default open | bool | |
89| placeholder | select placeholder | React Node | |
90| showSearch | whether show search input in single mode | bool | true |
91| showArrow | whether show arrow | bool | true (single mode), false (multiple mode) |
92| allowClear | whether allowClear | bool | false |
93| 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 |
94| tagRender | render custom tags. | (props: CustomTagProps) => ReactNode | - |
95| maxTagTextLength | max tag text length to show | number | - |
96| maxTagCount | max tag count to show | number | - |
97| maxTagPlaceholder | placeholder for omitted values | ReactNode/function(omittedValues) | - |
98| combobox | enable combobox mode(can not set multiple at the same time) | bool | false |
99| multiple | whether multiple select | bool | false |
100| disabled | whether disabled select | bool | false |
101| filterOption | whether filter options by input value. default filter by option's optionFilterProp prop's value | bool | true/Function(inputValue:string, option:Option) |
102| optionFilterProp | which prop value of option will be used for filter if filterOption is true | String | 'value' |
103| filterSort | Sort function for search options sorting, see [Array.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)'s compareFunction. | Function(optionA:Option, optionB: Option) | - |
104| optionLabelProp | render option value or option children as content of select | String: 'value'/'children' | 'value' |
105| defaultValue | initial selected option(s) | String/Array<String> | - |
106| value | current selected option(s) | String/Array<String>/{key:String, label:React.Node}/Array<{key, label}> | - |
107| labelInValue | whether to embed label in value, see above value type. Not support `combobox` mode | Bool | false |
108| backfill | whether backfill select option to search input (Only works in single and combobox mode) | Bool | false |
109| onChange | called when select an option or input value change(combobox) | function(value, option:Option/Array<Option>) | - |
110| onSearch | called when input changed | function | - |
111| onBlur | called when blur | function | - |
112| onFocus | called when focus | function | - |
113| onPopupScroll | called when menu is scrolled | function | - |
114| onSelect | called when a option is selected. param is option's value and option instance | Function(value, option:Option) | - |
115| onDeselect | called when a option is deselected. param is option's value. only called for multiple or tags | Function(value, option:Option) | - |
116| onInputKeyDown | called when key down on input | Function(event) | - |
117| defaultActiveFirstOption | whether active first option by default | bool | true |
118| getPopupContainer | container which popup select menu rendered into | function(trigger:Node):Node | function(){return document.body;} |
119| getInputElement | customize input element | function(): Element | - |
120| showAction | actions trigger the dropdown to show | String[]? | - |
121| autoFocus | focus select after mount | Bool | - |
122| autoClearSearchValue | auto clear search input value when multiple select is selected/deselected | boolean | true |
123| inputIcon | specify the select arrow icon | ReactNode | - |
124| clearIcon | specify the clear icon | ReactNode | - |
125| removeIcon | specify the remove icon | ReactNode | - |
126| menuItemSelectedIcon | specify the remove icon | ReactNode \| (props: MenuItemProps) => ReactNode | - |
127| dropdownRender | render custom dropdown menu | (menu: React.Node, props: MenuProps) => ReactNode | - |
128| loading | show loading icon in arrow | Boolean | false |
129| virtual | Disable virtual scroll | Boolean | true |
130| direction | direction of dropdown | 'ltr' \| 'rtl' | 'ltr' |
131
132### Methods
133
134| name | description | parameters | return |
135| ----- | ------------------------- | ---------- | ------ |
136| focus | focus select programmably | - | - |
137| blur | blur select programmably | - | - |
138
139### Option props
140
141| name | description | type | default |
142| --- | --- | --- | --- |
143| className | additional class to option | String | '' |
144| disabled | no effect for click or keydown for this item | bool | false |
145| key | if react want you to set key, then key is same as value, you can omit value | String/number | - |
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/number | - |
147| 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 | - |
148
149### OptGroup props
150
151| name | description | type | default |
152| --- | --- | --- | --- |
153| label | group label | String/React.Element | - |
154| key | - | String | - |
155| value | default filter by this attribute. if react want you to set key, then key is same as value, you can omit value | String | - |
156
157## Development
158
159```
160npm install
161npm start
162```
163
164## Example
165
166local example: http://localhost:9001/
167
168online example: http://select.react-component.now.sh/
169
170## Test Case
171
172```
173npm test
174```
175
176## Coverage
177
178```
179npm run coverage
180```
181
182## License
183
184rc-select is released under the MIT license.