Skip to content

Commit c3b8905

Browse files
Scroll selected option into view when receiving refs
1 parent 17ab36e commit c3b8905

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

packages/react-select/src/Select.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,16 @@ export default class Select<
668668
focusedOptionRef: HTMLDivElement | null = null;
669669
getFocusedOptionRef: RefCallback<HTMLDivElement> = (ref) => {
670670
this.focusedOptionRef = ref;
671+
if (this.menuListRef && this.focusedOptionRef) {
672+
scrollIntoView(this.menuListRef, this.focusedOptionRef);
673+
}
671674
};
672675
menuListRef: HTMLDivElement | null = null;
673676
getMenuListRef: RefCallback<HTMLDivElement> = (ref) => {
674677
this.menuListRef = ref;
678+
if (this.menuListRef && this.focusedOptionRef) {
679+
scrollIntoView(this.menuListRef, this.focusedOptionRef);
680+
}
675681
};
676682
inputRef: HTMLInputElement | null = null;
677683
getInputRef: RefCallback<HTMLInputElement> = (ref) => {

0 commit comments

Comments
 (0)