Skip to content

Commit 0671abb

Browse files
committed
[Autocomplete] Fix group labels hiding items during keybd navigation
While scrolling up with the keyboard, position the top part of the option so that the both the group label and the row are fully visible. No changes were made for the scroll down behaviour, which already handled skipping the group label. Doesn't interfere with the current behaviour of autoselects without groups. The 1.3 ratio was selected through visual inspection, and is the value that minimizes misaligments and/or cropping of the topmost option.
1 parent f1080b6 commit 0671abb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,11 @@ export default function useAutocomplete(props) {
182182
const elementBottom = element.offsetTop + element.offsetHeight;
183183
if (elementBottom > scrollBottom) {
184184
listboxNode.scrollTop = elementBottom - listboxNode.clientHeight;
185-
} else if (element.offsetTop < listboxNode.scrollTop) {
186-
listboxNode.scrollTop = element.offsetTop;
185+
} else if (
186+
element.offsetTop - element.offsetHeight * (groupBy ? 1.3 : 0) <
187+
listboxNode.scrollTop
188+
) {
189+
listboxNode.scrollTop = element.offsetTop - element.offsetHeight * (groupBy ? 1.3 : 0);
187190
}
188191
}
189192
}

0 commit comments

Comments
 (0)