@@ -108,9 +108,7 @@ const OptionList: React.RefForwardingComponent<
108
108
return - 1 ;
109
109
} ;
110
110
111
- const [ activeIndex , setActiveIndex ] = React . useState ( ( ) =>
112
- getEnabledActiveIndex ( 0 ) ,
113
- ) ;
111
+ const [ activeIndex , setActiveIndex ] = React . useState ( ( ) => getEnabledActiveIndex ( 0 ) ) ;
114
112
const setActive = ( index : number ) => {
115
113
setActiveIndex ( index ) ;
116
114
@@ -126,9 +124,7 @@ const OptionList: React.RefForwardingComponent<
126
124
127
125
// Auto active first item when list length or searchValue changed
128
126
React . useEffect ( ( ) => {
129
- setActive (
130
- defaultActiveFirstOption !== false ? getEnabledActiveIndex ( 0 ) : - 1 ,
131
- ) ;
127
+ setActive ( defaultActiveFirstOption !== false ? getEnabledActiveIndex ( 0 ) : - 1 ) ;
132
128
} , [ memoFlattenOptions . length , searchValue ] ) ;
133
129
134
130
// Auto scroll to item position in single mode
@@ -171,10 +167,7 @@ const OptionList: React.RefForwardingComponent<
171
167
}
172
168
173
169
if ( offset !== 0 ) {
174
- const nextActiveIndex = getEnabledActiveIndex (
175
- activeIndex + offset ,
176
- offset ,
177
- ) ;
170
+ const nextActiveIndex = getEnabledActiveIndex ( activeIndex + offset , offset ) ;
178
171
scrollIntoView ( nextActiveIndex ) ;
179
172
setActive ( nextActiveIndex ) ;
180
173
}
@@ -226,24 +219,15 @@ const OptionList: React.RefForwardingComponent<
226
219
const item = memoFlattenOptions [ index ] ;
227
220
const value = item && ( item . data as OptionData ) . value ;
228
221
return item ? (
229
- < div
230
- key = { index }
231
- role = "option"
232
- id = { `${ id } _list_${ index } ` }
233
- aria-selected = { values . has ( value ) }
234
- >
222
+ < div key = { index } role = "option" id = { `${ id } _list_${ index } ` } aria-selected = { values . has ( value ) } >
235
223
{ value }
236
224
</ div >
237
225
) : null ;
238
226
}
239
227
240
228
return (
241
229
< >
242
- < div
243
- role = "listbox"
244
- id = { `${ id } _list` }
245
- style = { { height : 0 , overflow : 'hidden' } }
246
- >
230
+ < div role = "listbox" id = { `${ id } _list` } style = { { height : 0 , overflow : 'hidden' } } >
247
231
{ renderItem ( activeIndex - 1 ) }
248
232
{ renderItem ( activeIndex ) }
249
233
{ renderItem ( activeIndex + 1 ) }
@@ -265,9 +249,7 @@ const OptionList: React.RefForwardingComponent<
265
249
// Group
266
250
if ( group ) {
267
251
return (
268
- < div
269
- className = { classNames ( itemPrefixCls , `${ itemPrefixCls } -group` ) }
270
- >
252
+ < div className = { classNames ( itemPrefixCls , `${ itemPrefixCls } -group` ) } >
271
253
{ label !== undefined ? label : key }
272
254
</ div >
273
255
) ;
@@ -280,34 +262,28 @@ const OptionList: React.RefForwardingComponent<
280
262
children,
281
263
style,
282
264
className,
265
+ ...otherProps
283
266
} = data as OptionData ;
284
267
285
268
// Option
286
269
const selected = values . has ( value ) ;
287
270
288
271
const optionPrefixCls = `${ itemPrefixCls } -option` ;
289
- const optionClassName = classNames (
290
- itemPrefixCls ,
291
- optionPrefixCls ,
292
- className ,
293
- {
294
- [ `${ optionPrefixCls } -grouped` ] : groupOption ,
295
- [ `${ optionPrefixCls } -active` ] :
296
- activeIndex === itemIndex && ! disabled ,
297
- [ `${ optionPrefixCls } -disabled` ] : disabled ,
298
- [ `${ optionPrefixCls } -selected` ] : selected ,
299
- } ,
300
- ) ;
272
+ const optionClassName = classNames ( itemPrefixCls , optionPrefixCls , className , {
273
+ [ `${ optionPrefixCls } -grouped` ] : groupOption ,
274
+ [ `${ optionPrefixCls } -active` ] : activeIndex === itemIndex && ! disabled ,
275
+ [ `${ optionPrefixCls } -disabled` ] : disabled ,
276
+ [ `${ optionPrefixCls } -selected` ] : selected ,
277
+ } ) ;
301
278
302
279
const mergedLabel = childrenAsData ? children : label ;
303
280
304
281
const iconVisible =
305
- ! menuItemSelectedIcon ||
306
- typeof menuItemSelectedIcon === 'function' ||
307
- selected ;
282
+ ! menuItemSelectedIcon || typeof menuItemSelectedIcon === 'function' || selected ;
308
283
309
284
return (
310
285
< div
286
+ { ...otherProps }
311
287
aria-selected = { selected }
312
288
className = { optionClassName }
313
289
title = { title }
@@ -325,9 +301,7 @@ const OptionList: React.RefForwardingComponent<
325
301
} }
326
302
style = { style }
327
303
>
328
- < div className = { `${ optionPrefixCls } -content` } >
329
- { mergedLabel || value }
330
- </ div >
304
+ < div className = { `${ optionPrefixCls } -content` } > { mergedLabel || value } </ div >
331
305
{ React . isValidElement ( menuItemSelectedIcon ) || selected }
332
306
{ iconVisible && (
333
307
< TransBtn
@@ -346,10 +320,9 @@ const OptionList: React.RefForwardingComponent<
346
320
) ;
347
321
} ;
348
322
349
- const RefOptionList = React . forwardRef <
350
- RefOptionListProps ,
351
- OptionListProps < SelectOptionsType >
352
- > ( OptionList ) ;
323
+ const RefOptionList = React . forwardRef < RefOptionListProps , OptionListProps < SelectOptionsType > > (
324
+ OptionList ,
325
+ ) ;
353
326
RefOptionList . displayName = 'OptionList' ;
354
327
355
328
export default RefOptionList ;
0 commit comments