Repository navigation
Description
Steps to reproduce
Live example: https://stackblitz.com/edit/vitejs-vite-qrvv2tm3?file=src%2FApp.tsx
The example renders react-window 2's List as the listbox element, so the listbox is the element that scrolls:
import Autocomplete from '@mui/material/Autocomplete';
import TextField from '@mui/material/TextField';
import * as React from 'react';
import { List, type RowComponentProps } from 'react-window';
type OptionElement = React.ReactElement<React.HTMLAttributes<HTMLElement>>;
function Row({ index, style, options }: RowComponentProps<{ options: OptionElement[] }>) {
const option = options[index];
return React.cloneElement(option, { style: { ...option.props.style, ...style } });
}
function Listbox({
children,
style,
ref,
...other
}: React.HTMLAttributes<HTMLElement> & { ref?: React.Ref<HTMLElement> }) {
const options = React.Children.toArray(children) as OptionElement[];
return (
<List
{...other}
listRef={(api) => {
if (typeof ref === 'function') ref(api?.element ?? null);
}}
rowComponent={Row}
rowProps={{ options }}
rowCount={options.length}
rowHeight={36}
tagName="ul"
style={{ ...style, maxHeight: undefined }}
/>
);
}
const OPTIONS = Array.from({ length: 1000 }, (_, i) => `Option ${i + 1}`);
export default function Demo() {
return (
<Autocomplete
sx={{ width: 300 }}
options={OPTIONS}
renderInput={(params) => <TextField {...params} label="1,000 options" />}
slotProps={{ listbox: { component: Listbox } }}
/>
);
}- Open the preview in its own browser tab, so that the key presses reach it.
- Click the input.
- Press the Down arrow about 20 times.
Current behavior
The highlighted option moves below the visible part of the listbox, and the listbox does not scroll. When the highlight passes the last option that react-window has rendered, the next key press moves the highlight back to the first option.
Expected behavior
The listbox scrolls to keep the highlighted option in view, as it does for an Autocomplete that is not virtualised.
Context
useAutocomplete scrolls the highlighted option into view with the option's offsetTop (source). offsetTop ignores CSS transforms.
react-window 2 positions each row with transform: translateY(...). The TanStack Virtual examples position rows the same way. In such a listbox, every option has an offsetTop of 0. The scroll code then finds that the option is already in view and does not scroll.
The Virtualization demo avoids the scroll code. Its List scrolls inside the listbox element, so the listbox element itself never scrolls. The demo then passes onHighlightChange, keeps a map from each option to its row index, and calls react-window's scrollToRow. Each app that virtualises an Autocomplete copies that code.
A possible fix is to measure the option with getBoundingClientRect() relative to the listbox, because that measurement includes transforms:
const listboxRect = listboxNode.getBoundingClientRect();
const optionRect = option.getBoundingClientRect();
const optionTop = optionRect.top - listboxRect.top - listboxNode.clientTop + listboxNode.scrollTop;
const optionBottom = optionTop + optionRect.height;With this change, the listbox in the example keeps the highlighted option in view with no onHighlightChange code. We have not tested this patch in MUI. We tested the effect from the other side: when the row component converts react-window's translateY to top, the example scrolls correctly with the current MUI code.
This issue is only about the scroll. A separate limit stays: Home, End and wrap-around skip options that are not in the DOM, because validOptionIndex treats a missing option as disabled.
Your environment
- @mui/material 9.5.0
- react-window 2.5.0
- React 19.3.1
- Chrome 154, macOS
Search keywords: autocomplete virtualization offsetTop transform react-window scroll keyboard
Activity
pavstev commentedon Nov 3, 2026
I can reproduce this on current
masterwith react-window 2.3.4 (the version indocs/package.json) in Chromium, Firefox and WebKit: every row getstransform: translateY(...)and the sameoffsetTopof 8, so the highlight leaves the listbox after about 10 ArrowDown presses. I'd measure the option against the listbox insyncHighlightedIndexToDOMand keep the rest of the scroll block as it is;scalekeeps layout pixels when an ancestor is scaled, and the< 1check is there becauseoffsetHeightis rounded:I compared it with
masteron the default,groupBy, bordered anddisablePortallistboxes, and thescrollTopafter every arrow, Page, Home and End key is the same as before in all three browsers. I left outscrollIntoView({ block: 'nearest' })because it would also scroll the page and ignore the group header offset. @silviuaavram, would you take a PR with this change and two browser tests (plain, and inside a scaled ancestor)?jiwoo1222 commentedon Nov 7, 2026
I’m going to prepare a focused fix and regression coverage for transform-positioned virtualized listbox options, based on the reproduction and geometry approach discussed here.
pavstev commentedon Nov 10, 2026
There is already a PR for this, #49663, open since 3 Nov. It has the
getBoundingClientRectchange from the issue and two browser tests (plain transform, and inside a scaled ancestor). All tests and builds pass, and it merges cleanly into currentmaster. @jiwoo1222, if you see a gap in it, a review comment there would help most, and I will adjust the PR.ZeeshanTamboli commentedon Nov 12, 2026
Thanks for reporting. It seems like a bug.
github-actions commentedon Nov 13, 2026
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.
@micmcg Thanks again for creating this issue! If you have a moment, we would love to hear your thoughts on how we handled it with this short feedback form.