From 47985eb70da80b7dc889a165c2babf9f96645049 Mon Sep 17 00:00:00 2001 From: js0753 Date: Wed, 7 May 2025 04:54:48 -0400 Subject: [PATCH] fix: Select dropdown should scroll to the option with the closest prefix to the searched value. --- src/OptionList.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/OptionList.tsx b/src/OptionList.tsx index 78abe706b..fdcf12ff6 100644 --- a/src/OptionList.tsx +++ b/src/OptionList.tsx @@ -157,7 +157,10 @@ const OptionList: React.ForwardRefRenderFunction = (_, r const timeoutId = setTimeout(() => { if (!multiple && open && rawValues.size === 1) { const value: RawValueType = Array.from(rawValues)[0]; - const index = memoFlattenOptions.findIndex(({ data }) => data.value === value); + // Scroll to the option closest to the searchValue if searching. + const index = memoFlattenOptions.findIndex(({ data }) => + searchValue ? String(data.value).startsWith(searchValue) : data.value === value, + ); if (index !== -1) { setActive(index);