Skip to content

Commit 02d80ba

Browse files
Scroll selected option into view when receiving refs
1 parent 2f94e8d commit 02d80ba

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
@@ -620,10 +620,16 @@ export default class Select<
620620
focusedOptionRef: HTMLDivElement | null = null;
621621
getFocusedOptionRef: RefCallback<HTMLDivElement> = (ref) => {
622622
this.focusedOptionRef = ref;
623+
if (this.menuListRef && this.focusedOptionRef) {
624+
scrollIntoView(this.menuListRef, this.focusedOptionRef);
625+
}
623626
};
624627
menuListRef: HTMLDivElement | null = null;
625628
getMenuListRef: RefCallback<HTMLDivElement> = (ref) => {
626629
this.menuListRef = ref;
630+
if (this.menuListRef && this.focusedOptionRef) {
631+
scrollIntoView(this.menuListRef, this.focusedOptionRef);
632+
}
627633
};
628634
inputRef: HTMLInputElement | null = null;
629635
getInputRef: RefCallback<HTMLInputElement> = (ref) => {

0 commit comments

Comments
 (0)