@@ -57,7 +57,6 @@ function handleSearch(e) {
57
57
maxTagCount= {6 }
58
58
allowClear
59
59
value= {values}
60
- disabled= {false }
61
60
placeholder= " 请输入选择"
62
61
onSearch= {handleSearch}
63
62
// onSelect={(value)=>console.log('onSelect',value)}
@@ -78,7 +77,6 @@ function handleSearch(e) {
78
77
maxTagCount= {6 }
79
78
allowClear
80
79
value= {value}
81
- disabled= {false }
82
80
placeholder= " 请输入选择"
83
81
onSearch= {handleSearch}
84
82
// onSelect={(value)=>console.log('onSelect',value)}
@@ -90,6 +88,14 @@ function handleSearch(e) {
90
88
}}
91
89
/ >
92
90
< / Row>
91
+ < Row>
92
+ < SearchSelect
93
+ mode= " single"
94
+ style= {{ width: 200 }}
95
+ placeholder= " 请输入选择"
96
+ disabled= {true }
97
+ / >
98
+ < / Row>
93
99
< / Row>
94
100
);
95
101
};
@@ -115,11 +121,10 @@ const Demo = () => {
115
121
{ label: ' a8' , value: 8 },
116
122
]
117
123
124
+ const valueAmount = 2
118
125
const [option , setOption ] = React .useState (selectOption);
119
126
const [loading , setLoading ] = React .useState (false );
120
- const [values , setValues ] = React .useState ([{label: ' a7' , value: 7 }]);
121
- const [disabled , setDisabled ] = React .useState (false );
122
- const maxTagCount = 2
127
+ const [values , setValues ] = React .useState ([ 1 , 2 , 7 ]);
123
128
124
129
function handleSearch (e ) {
125
130
setLoading (true )
@@ -131,7 +136,70 @@ const Demo = () => {
131
136
}
132
137
133
138
return (
134
- < Row gutter= {20 }>
139
+ < Row style= {{ marginLeft: 10 }}>
140
+ < SearchSelect
141
+ mode= " multiple"
142
+ style= {{ width: 200 }}
143
+ showSearch= {true }
144
+ valueAmount= {valueAmount}
145
+ allowClear
146
+ value= {values}
147
+ placeholder= " 请输入选择"
148
+ onSearch= {handleSearch}
149
+ // onSelect={(value)=>console.log('onSelect',value)}
150
+ loading= {loading}
151
+ option= {option}
152
+ onChange= {(value ) => {
153
+ setValues (value)
154
+ }}
155
+ / >
156
+ < / Row>
157
+ );
158
+ };
159
+ ReactDOM .render (< Demo / > , _mount_);
160
+ ```
161
+
162
+ ## 显示最大数量
163
+
164
+ <!-- rehype:bgWhite=true&codeSandbox=true&codePen=true-->
165
+ ``` jsx
166
+ import ReactDOM from ' react-dom' ;
167
+ import { SearchSelect ,Row ,Col } from ' uiw' ;
168
+
169
+ const Demo = () => {
170
+ const selectOption = [
171
+ { label: ' a1' , value: 1 },
172
+ { label: ' a2' , value: 2 },
173
+ { label: ' a3' , value: 3 },
174
+ { label: ' a4' , value: 4 },
175
+ { label: ' a5' , value: 5 },
176
+ { label: ' a6' , value: 6 },
177
+ { label: ' a7' , value: 7 },
178
+ { label: ' a8' , value: 8 },
179
+ ]
180
+
181
+ const maxTagCount = 4
182
+ const [option , setOption ] = React .useState (selectOption);
183
+ const [loading , setLoading ] = React .useState (false );
184
+ const [values , setValues ] = React .useState ([
185
+ { label: ' a1' , value: 1 },
186
+ { label: ' a2' , value: 2 },
187
+ { label: ' a5' , value: 5 },
188
+ { label: ' a7' , value: 7 },
189
+ { label: ' a8' , value: 8 },
190
+ ]);
191
+
192
+ function handleSearch (e ) {
193
+ setLoading (true )
194
+ setTimeout (() => {
195
+ const filterOpion = selectOption .filter (item => !! item .label .includes (e .trim ()))
196
+ setOption ([... filterOpion]);
197
+ setLoading (false );
198
+ }, 500 );
199
+ }
200
+
201
+ return (
202
+ < Row style= {{ marginLeft: 10 }}>
135
203
< SearchSelect
136
204
mode= " multiple"
137
205
style= {{ width: 200 }}
@@ -140,15 +208,11 @@ const Demo = () => {
140
208
maxTagCount= {maxTagCount}
141
209
allowClear
142
210
value= {values}
143
- disabled= {disabled}
144
211
placeholder= " 请输入选择"
145
212
onSearch= {handleSearch}
146
- // onSelect={(value)=>console.log('onSelect',value)}
147
213
loading= {loading}
148
214
option= {option}
149
215
onChange= {(value ) => {
150
- if (value? .length >= maxTagCount)
151
- setDisabled (true )
152
216
setValues (value)
153
217
}}
154
218
/ >
@@ -158,6 +222,47 @@ const Demo = () => {
158
222
ReactDOM .render (< Demo / > , _mount_);
159
223
```
160
224
225
+ ## 不可搜索
226
+
227
+ <!-- rehype:bgWhite=true&codeSandbox=true&codePen=true-->
228
+ ``` jsx
229
+ import ReactDOM from ' react-dom' ;
230
+ import { SearchSelect ,Row ,Col } from ' uiw' ;
231
+
232
+ const Demo = () => {
233
+ const selectOption = [
234
+ { label: ' a1' , value: 1 },
235
+ { label: ' a2' , value: 2 },
236
+ { label: ' a3' , value: 3 },
237
+ { label: ' a4' , value: 4 },
238
+ { label: ' a5' , value: 5 },
239
+ { label: ' a6' , value: 6 },
240
+ { label: ' a7' , value: 7 },
241
+ { label: ' a8' , value: 8 },
242
+ ]
243
+
244
+ const [values , setValues ] = React .useState ([1 ,7 ]);
245
+
246
+ return (
247
+ < Row style= {{ marginLeft: 10 }}>
248
+ < SearchSelect
249
+ mode= " multiple"
250
+ style= {{ width: 200 }}
251
+ showSearch= {true }
252
+ labelInValue= {false }
253
+ showSearch= {false }
254
+ placeholder= " 请输入选择"
255
+ value= {values}
256
+ option= {selectOption}
257
+ onChange= {(value ) => {
258
+ setValues (value)
259
+ }}
260
+ / >
261
+ < / Row>
262
+ );
263
+ };
264
+ ReactDOM .render (< Demo / > , _mount_);
265
+ ```
161
266
162
267
### 在表单中使用
163
268
@@ -307,3 +412,4 @@ ReactDOM.render(<Demo />, _mount_);
307
412
| onSearch | 文本框值变化时回调 | function(value: String) | - | - |
308
413
| onSelect | 被选中时调用,参数为选中项的 value | function(value: String/Number ) | - | - |
309
414
| loading | 加载中状态 | Boolean | ` false ` | - |
415
+ | valueAmount | 多选模式下,限制最多选择多少个(value的长度) | number | - | - |
0 commit comments