@@ -22,6 +22,7 @@ import {
2222 EMPTY_ARRAY ,
2323 DEFAULT_THEME ,
2424 SELECT_WRAPPER_ATTRS ,
25+ PAGE_SIZE_DEFAULT ,
2526 PLACEHOLDER_DEFAULT ,
2627 LOADING_MSG_DEFAULT ,
2728 CONTROL_CONTAINER_CLS ,
@@ -222,7 +223,6 @@ const Select = forwardRef<SelectRef, SelectProps>((
222223 hideSelectedOptions,
223224 getIsOptionDisabled,
224225 getFilterOptionString,
225- pageSize = 5 ,
226226 isSearchable = true ,
227227 memoOptions = false ,
228228 lazyLoadMenu = false ,
@@ -235,6 +235,7 @@ const Select = forwardRef<SelectRef, SelectProps>((
235235 filterMatchFrom = FilterMatchEnum . ANY ,
236236 menuPosition = MenuPositionEnum . BOTTOM ,
237237 options = EMPTY_ARRAY ,
238+ pageSize = PAGE_SIZE_DEFAULT ,
238239 loadingMsg = LOADING_MSG_DEFAULT ,
239240 placeholder = PLACEHOLDER_DEFAULT ,
240241 noOptionsMsg = NO_OPTIONS_MSG_DEFAULT ,
@@ -333,12 +334,12 @@ const Select = forwardRef<SelectRef, SelectProps>((
333334 return ;
334335 }
335336
336- const selectedIndex = ! isMulti
337+ const selectedIdx = ! isMulti
337338 ? menuOptions . findIndex ( ( x ) => x . isSelected )
338339 : - 1 ;
339340
340- const index = selectedIndex > - 1
341- ? selectedIndex
341+ const index = selectedIdx > - 1
342+ ? selectedIdx
342343 : position === OptionIndexEnum . FIRST
343344 ? 0
344345 : menuOptions . length - 1 ;
@@ -388,11 +389,12 @@ const Select = forwardRef<SelectRef, SelectProps>((
388389 setFocusedOption ( FOCUSED_OPTION_DEFAULT ) ;
389390 } ,
390391 setValue : ( option ?: OptionData ) => {
391- const normalizedOpts = normalizeValue ( option , getOptionValueFn , getOptionLabelFn ) ;
392- setSelectedOption ( normalizedOpts ) ;
392+ setSelectedOption (
393+ normalizeValue ( option , getOptionValueFn , getOptionLabelFn )
394+ ) ;
393395 } ,
394396 toggleMenu : ( state ?: boolean ) => {
395- if ( state === true || ( state === undefined && ! menuOpenRef . current ) ) {
397+ if ( state || ( state === undefined && ! menuOpenRef . current ) ) {
396398 focusInput ( ) ;
397399 openMenuAndFocusOption ( OptionIndexEnum . FIRST ) ;
398400 } else {
@@ -474,24 +476,24 @@ const Select = forwardRef<SelectRef, SelectProps>((
474476 const focusValueOnArrowKey = ( key : string ) : void => {
475477 if ( ! hasSelectedOptions ) return ;
476478
477- let nextFocusedIdx = - 1 ;
479+ let focusedIdx = - 1 ;
478480 const lastValueIdx = selectedOption . length - 1 ;
479481 const curFocusedIdx = focusedMultiValue ? selectedOption . findIndex ( ( x ) => x . value === focusedMultiValue ) : - 1 ;
480482
481483 if ( key === 'ArrowRight' ) {
482- nextFocusedIdx = ( curFocusedIdx > - 1 && curFocusedIdx < lastValueIdx )
484+ focusedIdx = ( curFocusedIdx > - 1 && curFocusedIdx < lastValueIdx )
483485 ? curFocusedIdx + 1
484486 : - 1 ;
485487 } else {
486- nextFocusedIdx = curFocusedIdx !== 0
488+ focusedIdx = curFocusedIdx !== 0
487489 ? curFocusedIdx === - 1
488490 ? lastValueIdx
489491 : curFocusedIdx - 1
490492 : 0 ;
491493 }
492494
493- const nextFocusedVal = nextFocusedIdx >= 0
494- ? selectedOption [ nextFocusedIdx ] . value !
495+ const nextFocusedVal = focusedIdx >= 0
496+ ? selectedOption [ focusedIdx ] . value !
495497 : null ;
496498
497499 if ( focusedOption . data ) setFocusedOption ( FOCUSED_OPTION_DEFAULT ) ;
@@ -512,13 +514,13 @@ const Select = forwardRef<SelectRef, SelectProps>((
512514 break ;
513515 }
514516 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 ;
517519 break ;
518520 }
519521 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 ;
522524 break ;
523525 }
524526 }
@@ -599,14 +601,13 @@ const Select = forwardRef<SelectRef, SelectProps>((
599601 if ( inputValue ) return ;
600602
601603 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 ;
607608
608609 removeSelectedOption ( focusedMultiValue ) ;
609- setFocusedMultiValue ( nexFocusedMultiValue ) ;
610+ setFocusedMultiValue ( nextFocusedMultiValue ) ;
610611 } else {
611612 if ( ! backspaceClearsValue ) return ;
612613 if ( ! hasSelectedOptions ) break ;
@@ -681,6 +682,7 @@ const Select = forwardRef<SelectRef, SelectProps>((
681682 menuOpenRef . current ? setMenuOpen ( false ) : openMenuAndFocusOption ( OptionIndexEnum . FIRST ) ;
682683 } , [ isDisabled , openMenuOnClick , openMenuAndFocusOption ] ) ;
683684
685+ const flexValueWrapper = ! ! isMulti && hasSelectedOptions ;
684686 const showClear = ! ! isClearable && ! isDisabled && hasSelectedOptions ;
685687 const inputReadOnly = isDisabled || ! isSearchable || ! ! focusedMultiValue ;
686688
@@ -702,7 +704,7 @@ const Select = forwardRef<SelectRef, SelectProps>((
702704 onMouseDown = { handleOnControlMouseDown }
703705 data-testid = { CONTROL_CONTAINER_TESTID }
704706 >
705- < ValueWrapper flex = { ! ! isMulti && hasSelectedOptions } >
707+ < ValueWrapper flex = { flexValueWrapper } >
706708 < Value
707709 isMulti = { isMulti }
708710 inputValue = { inputValue }
0 commit comments