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