UNPKG

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