Skip to content

Commit c00c681

Browse files
authored
fix: Select dropdown should scroll to the option with the closest prefix to the searched value. (#1146)
1 parent 27a225e commit c00c681

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
@@ -157,7 +157,10 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
157157
const timeoutId = setTimeout(() => {
158158
if (!multiple && open && rawValues.size === 1) {
159159
const value: RawValueType = Array.from(rawValues)[0];
160-
const index = memoFlattenOptions.findIndex(({ data }) => data.value === value);
160+
// Scroll to the option closest to the searchValue if searching.
161+
const index = memoFlattenOptions.findIndex(({ data }) =>
162+
searchValue ? String(data.value).startsWith(searchValue) : data.value === value,
163+
);
161164

162165
if (index !== -1) {
163166
setActive(index);

0 commit comments

Comments
 (0)