Skip to content

Commit d8296ab

Browse files
js0753afc163
authored andcommitted
fix: Select dropdown should scroll to the option with the closest prefix to the searched value. (#1146)
1 parent e53f6db commit d8296ab

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/OptionList.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
154154
const timeoutId = setTimeout(() => {
155155
if (!multiple && open && rawValues.size === 1) {
156156
const value: RawValueType = Array.from(rawValues)[0];
157-
const index = memoFlattenOptions.findIndex(({ data }) => data.value === value);
157+
// Scroll to the option closest to the searchValue if searching.
158+
const index = memoFlattenOptions.findIndex(({ data }) =>
159+
searchValue ? String(data.value).startsWith(searchValue) : data.value === value,
160+
);
158161

159162
if (index !== -1) {
160163
setActive(index);

0 commit comments

Comments
 (0)