From c3b890523d61ba1b87e5820deadc59480c0ca5b7 Mon Sep 17 00:00:00 2001 From: JefHellemansBlockbax <141717908+JefHellemansBlockbax@users.noreply.github.com> Date: Thu, 19 Oct 2023 14:23:51 +0000 Subject: [PATCH] Scroll selected option into view when receiving refs --- packages/react-select/src/Select.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/react-select/src/Select.tsx b/packages/react-select/src/Select.tsx index 798f6126b2..b78122e530 100644 --- a/packages/react-select/src/Select.tsx +++ b/packages/react-select/src/Select.tsx @@ -668,10 +668,16 @@ export default class Select< focusedOptionRef: HTMLDivElement | null = null; getFocusedOptionRef: RefCallback = (ref) => { this.focusedOptionRef = ref; + if (this.menuListRef && this.focusedOptionRef) { + scrollIntoView(this.menuListRef, this.focusedOptionRef); + } }; menuListRef: HTMLDivElement | null = null; getMenuListRef: RefCallback = (ref) => { this.menuListRef = ref; + if (this.menuListRef && this.focusedOptionRef) { + scrollIntoView(this.menuListRef, this.focusedOptionRef); + } }; inputRef: HTMLInputElement | null = null; getInputRef: RefCallback = (ref) => {