import { useEffect } from 'react' import MultiSelect from 'react-multiple-select-dropdown-lite' import type { MultiSelectListProps } from 'react-multiple-select-dropdown-lite' import 'react-multiple-select-dropdown-lite/dist/index.css' import { List, useListCallbackRef } from 'react-window' import type { RowComponentProps } from 'react-window' const options = Array.from({ length: 100_000 }, (_, i) => ({ label: `Item ${i + 1}`, value: `item-${i + 1}` })) const Row = ({ index, style, row }: RowComponentProps>) => ( // top, not react-window's transform: Firefox places a submenu off a transformed row
{row(index)}
) // renders only the rows in view export function VirtualList({ count, row, activeIndex }: MultiSelectListProps) { // state, not a ref: the list can scroll once it has mounted const [list, setList] = useListCallbackRef(null) // keeps the keyboard highlight in view useEffect(() => { activeIndex >= 0 && list?.scrollToRow({ index: activeIndex }) }, [list, activeIndex]) return ( ) } export default function VirtualListDemo() { return ( } /> ) }