[v11.1.x] Select: Fix scrolling virtualized menu on mobile (#90740)

Select: Fix scrolling virtualized menu on mobile (#90724)

pass select-menu innerRef to virtualized list

(cherry picked from commit dc30858e9d)
This commit is contained in:
Ashley Harrison
2024-07-22 15:59:46 +02:00
committed by GitHub
parent b4f4b3e9b4
commit 12a3a261a2
@@ -1,6 +1,6 @@
import { cx } from '@emotion/css';
import { max } from 'lodash';
import React, { RefCallback, useEffect, useMemo, useRef } from 'react';
import React, { RefCallback, useLayoutEffect, useMemo, useRef } from 'react';
import { MenuListProps } from 'react-select';
import { FixedSizeList as List } from 'react-window';
@@ -51,6 +51,7 @@ const VIRTUAL_LIST_WIDTH_EXTRA = 36;
export const VirtualizedSelectMenu = ({
children,
maxHeight,
innerRef: scrollRef,
options,
focusedOption,
}: MenuListProps<SelectableValue>) => {
@@ -70,7 +71,7 @@ export const VirtualizedSelectMenu = ({
const focusedIndex = flattenedOptions.findIndex(
(option: SelectableValue<unknown>) => option.value === focusedOption?.value
);
useEffect(() => {
useLayoutEffect(() => {
listRef.current?.scrollToItem(focusedIndex);
}, [focusedIndex]);
@@ -98,6 +99,7 @@ export const VirtualizedSelectMenu = ({
return (
<List
outerRef={scrollRef}
ref={listRef}
className={styles.menu}
height={heightEstimate}