@@ -29,7 +29,6 @@ import { convertSizeToRem } from '../inputv2/inputv2';
2929import { ConstrainedText } from '../constrainedtext/Constrainedtext.component' ;
3030import ReactSelect from 'react-select/src/Select' ;
3131
32- const ITEMS_PER_SCROLL_WINDOW = 4 ;
3332// more/equal than NOPT_SEARCH options enable search
3433const NOPT_SEARCH = 8 ;
3534export type OptionProps = {
@@ -236,6 +235,7 @@ const MenuList = (props) => {
236235 const listRef = useRef < FixedSizeList < any > | null > ( null ) ;
237236 const { children, getValue } = props ;
238237 const [ selectedOption ] = getValue ( ) ;
238+ const { itemsPerScrollWindow } = props . selectProps ;
239239 const optionHeight =
240240 convertRemToPixels (
241241 parseFloat ( props . selectProps . isDefault ? spacing . r40 : spacing . r24 ) ,
@@ -253,7 +253,7 @@ const MenuList = (props) => {
253253 }
254254
255255 const initialOffset =
256- selectedIndex * optionHeight - ( ITEMS_PER_SCROLL_WINDOW - 1 ) * optionHeight ;
256+ selectedIndex * optionHeight - ( itemsPerScrollWindow - 1 ) * optionHeight ;
257257 useEffect ( ( ) => {
258258 if ( listRef && listRef . current ) {
259259 listRef . current . scrollTo (
@@ -267,13 +267,13 @@ const MenuList = (props) => {
267267 }
268268 } , [ children . length , focusedIndex , optionHeight , listRef ] ) ;
269269
270- if ( children . length > ITEMS_PER_SCROLL_WINDOW ) {
270+ if ( children . length > itemsPerScrollWindow ) {
271271 return (
272272 // @ts -ignore
273273 < List
274274 ref = { listRef }
275275 className = "sc-select__menu-list"
276- height = { optionHeight * ITEMS_PER_SCROLL_WINDOW + optionHeight / 2 }
276+ height = { optionHeight * itemsPerScrollWindow + optionHeight / 2 }
277277 itemCount = { children . length }
278278 itemSize = { optionHeight }
279279 initialScrollOffset = { initialOffset }
@@ -349,6 +349,10 @@ export type SelectProps = {
349349 className ?: string ;
350350 /** use menuPositon='fixed' inside modal to avoid display issue */
351351 menuPosition ?: 'fixed' | 'absolute' ;
352+ /** number of items visible before the option list becomes scrollable
353+ * @default 4
354+ */
355+ itemsPerScrollWindow ?: number ;
352356} ;
353357
354358type SelectOptionProps = {
@@ -390,6 +394,7 @@ function SelectBox<
390394 size = '1' ,
391395 id,
392396 selectRef,
397+ itemsPerScrollWindow = 4 ,
393398 ...rest
394399} : SelectProps & {
395400 selectRef ?: Ref < SelectRef < OptionType , IsMulti , GroupType > > ;
@@ -526,7 +531,7 @@ function SelectBox<
526531 IndicatorSeparator : null ,
527532 } }
528533 isDefault = { isDefaultVariant }
529- ITEMS_PER_SCROLL_WINDOW = { ITEMS_PER_SCROLL_WINDOW }
534+ itemsPerScrollWindow = { itemsPerScrollWindow }
530535 onChange = { handleChange }
531536 onInputChange = { handleSearchInput }
532537 ref = { internalSelectRef }
0 commit comments