From 02d80baf47adba7cfa1348da92c9d9f8738c40c1 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 16daa33094..4ac0a483ad 100644 --- a/packages/react-select/src/Select.tsx +++ b/packages/react-select/src/Select.tsx @@ -620,10 +620,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) => {