@@ -22,6 +22,7 @@ import {
22
22
EMPTY_ARRAY ,
23
23
DEFAULT_THEME ,
24
24
SELECT_WRAPPER_ATTRS ,
25
+ PAGE_SIZE_DEFAULT ,
25
26
PLACEHOLDER_DEFAULT ,
26
27
LOADING_MSG_DEFAULT ,
27
28
CONTROL_CONTAINER_CLS ,
@@ -222,7 +223,6 @@ const Select = forwardRef<SelectRef, SelectProps>((
222
223
hideSelectedOptions,
223
224
getIsOptionDisabled,
224
225
getFilterOptionString,
225
- pageSize = 5 ,
226
226
isSearchable = true ,
227
227
memoOptions = false ,
228
228
lazyLoadMenu = false ,
@@ -235,6 +235,7 @@ const Select = forwardRef<SelectRef, SelectProps>((
235
235
filterMatchFrom = FilterMatchEnum . ANY ,
236
236
menuPosition = MenuPositionEnum . BOTTOM ,
237
237
options = EMPTY_ARRAY ,
238
+ pageSize = PAGE_SIZE_DEFAULT ,
238
239
loadingMsg = LOADING_MSG_DEFAULT ,
239
240
placeholder = PLACEHOLDER_DEFAULT ,
240
241
noOptionsMsg = NO_OPTIONS_MSG_DEFAULT ,
@@ -333,12 +334,12 @@ const Select = forwardRef<SelectRef, SelectProps>((
333
334
return ;
334
335
}
335
336
336
- const selectedIndex = ! isMulti
337
+ const selectedIdx = ! isMulti
337
338
? menuOptions . findIndex ( ( x ) => x . isSelected )
338
339
: - 1 ;
339
340
340
- const index = selectedIndex > - 1
341
- ? selectedIndex
341
+ const index = selectedIdx > - 1
342
+ ? selectedIdx
342
343
: position === OptionIndexEnum . FIRST
343
344
? 0
344
345
: menuOptions . length - 1 ;
@@ -388,11 +389,12 @@ const Select = forwardRef<SelectRef, SelectProps>((
388
389
setFocusedOption ( FOCUSED_OPTION_DEFAULT ) ;
389
390
} ,
390
391
setValue : ( option ?: OptionData ) => {
391
- const normalizedOpts = normalizeValue ( option , getOptionValueFn , getOptionLabelFn ) ;
392
- setSelectedOption ( normalizedOpts ) ;
392
+ setSelectedOption (
393
+ normalizeValue ( option , getOptionValueFn , getOptionLabelFn )
394
+ ) ;
393
395
} ,
394
396
toggleMenu : ( state ?: boolean ) => {
395
- if ( state === true || ( state === undefined && ! menuOpenRef . current ) ) {
397
+ if ( state || ( state === undefined && ! menuOpenRef . current ) ) {
396
398
focusInput ( ) ;
397
399
openMenuAndFocusOption ( OptionIndexEnum . FIRST ) ;
398
400
} else {
@@ -474,24 +476,24 @@ const Select = forwardRef<SelectRef, SelectProps>((
474
476
const focusValueOnArrowKey = ( key : string ) : void => {
475
477
if ( ! hasSelectedOptions ) return ;
476
478
477
- let nextFocusedIdx = - 1 ;
479
+ let focusedIdx = - 1 ;
478
480
const lastValueIdx = selectedOption . length - 1 ;
479
481
const curFocusedIdx = focusedMultiValue ? selectedOption . findIndex ( ( x ) => x . value === focusedMultiValue ) : - 1 ;
480
482
481
483
if ( key === 'ArrowRight' ) {
482
- nextFocusedIdx = ( curFocusedIdx > - 1 && curFocusedIdx < lastValueIdx )
484
+ focusedIdx = ( curFocusedIdx > - 1 && curFocusedIdx < lastValueIdx )
483
485
? curFocusedIdx + 1
484
486
: - 1 ;
485
487
} else {
486
- nextFocusedIdx = curFocusedIdx !== 0
488
+ focusedIdx = curFocusedIdx !== 0
487
489
? curFocusedIdx === - 1
488
490
? lastValueIdx
489
491
: curFocusedIdx - 1
490
492
: 0 ;
491
493
}
492
494
493
- const nextFocusedVal = nextFocusedIdx >= 0
494
- ? selectedOption [ nextFocusedIdx ] . value !
495
+ const nextFocusedVal = focusedIdx >= 0
496
+ ? selectedOption [ focusedIdx ] . value !
495
497
: null ;
496
498
497
499
if ( focusedOption . data ) setFocusedOption ( FOCUSED_OPTION_DEFAULT ) ;
@@ -512,13 +514,13 @@ const Select = forwardRef<SelectRef, SelectProps>((
512
514
break ;
513
515
}
514
516
case OptionIndexEnum . PAGEUP : {
515
- const pageIndex = focusedOption . index - pageSize ;
516
- index = ( pageIndex < 0 ) ? 0 : pageIndex ;
517
+ const pageIdx = focusedOption . index - pageSize ;
518
+ index = ( pageIdx < 0 ) ? 0 : pageIdx ;
517
519
break ;
518
520
}
519
521
case OptionIndexEnum . PAGEDOWN : {
520
- const pageIndex = focusedOption . index + pageSize ;
521
- index = ( pageIndex > menuOptions . length - 1 ) ? menuOptions . length - 1 : pageIndex ;
522
+ const pageIdx = focusedOption . index + pageSize ;
523
+ index = ( pageIdx > menuOptions . length - 1 ) ? menuOptions . length - 1 : pageIdx ;
522
524
break ;
523
525
}
524
526
}
@@ -599,14 +601,13 @@ const Select = forwardRef<SelectRef, SelectProps>((
599
601
if ( inputValue ) return ;
600
602
601
603
if ( focusedMultiValue ) {
602
- const clearFocusedIndex = selectedOption . findIndex ( ( x ) => x . value === focusedMultiValue ) ;
603
- const nexFocusedMultiValue =
604
- ( clearFocusedIndex > - 1 && ( clearFocusedIndex < ( selectedOption . length - 1 ) ) )
605
- ? selectedOption [ clearFocusedIndex + 1 ] . value !
606
- : null ;
604
+ const focusedIdx = selectedOption . findIndex ( ( x ) => x . value === focusedMultiValue ) ;
605
+ const nextFocusedMultiValue = ( focusedIdx > - 1 && ( focusedIdx < ( selectedOption . length - 1 ) ) )
606
+ ? selectedOption [ focusedIdx + 1 ] . value !
607
+ : null ;
607
608
608
609
removeSelectedOption ( focusedMultiValue ) ;
609
- setFocusedMultiValue ( nexFocusedMultiValue ) ;
610
+ setFocusedMultiValue ( nextFocusedMultiValue ) ;
610
611
} else {
611
612
if ( ! backspaceClearsValue ) return ;
612
613
if ( ! hasSelectedOptions ) break ;
@@ -681,6 +682,7 @@ const Select = forwardRef<SelectRef, SelectProps>((
681
682
menuOpenRef . current ? setMenuOpen ( false ) : openMenuAndFocusOption ( OptionIndexEnum . FIRST ) ;
682
683
} , [ isDisabled , openMenuOnClick , openMenuAndFocusOption ] ) ;
683
684
685
+ const flexValueWrapper = ! ! isMulti && hasSelectedOptions ;
684
686
const showClear = ! ! isClearable && ! isDisabled && hasSelectedOptions ;
685
687
const inputReadOnly = isDisabled || ! isSearchable || ! ! focusedMultiValue ;
686
688
@@ -702,7 +704,7 @@ const Select = forwardRef<SelectRef, SelectProps>((
702
704
onMouseDown = { handleOnControlMouseDown }
703
705
data-testid = { CONTROL_CONTAINER_TESTID }
704
706
>
705
- < ValueWrapper flex = { ! ! isMulti && hasSelectedOptions } >
707
+ < ValueWrapper flex = { flexValueWrapper } >
706
708
< Value
707
709
isMulti = { isMulti }
708
710
inputValue = { inputValue }
0 commit comments